google 地图上未显示标记

marker is not showing on google map

我在 iOS 中使用 GoogleMap SDK 来显示用户的当前位置。 Google 地图显示在我的视野中,但标记不可见。我不知道我在这里做错了什么。

这是我的代码

#import <GoogleMaps/GoogleMaps.h>
@interface firstViewController () {
   // GMSMapView *mapView_;
    IBOutlet GMSMapView *mapView_;
}
@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = NO;
    [self.view addSubview: mapView_];


    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
 }

为什么要用 CGRectZero 框架设置地图?

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = NO;
[self.view addSubview: mapView_];

如果您将地图的框架设置为 CGRectZero,地图将不可见。所以首先,尝试通过给它一个不同的框架来让你的 mapView 可见。

我不知道问题出在哪里,但我认为我在我的应用程序中实施的这种方法对您有帮助。

- (void)getCamerasWithNortheast:(CLLocationCoordinate2D)neCoord southwest:(CLLocationCoordinate2D)swCoord fromDutation:(int)fromDuration
{
    NSString* urlString = nil;
    if(fromDuration == 0)
    {
        urlString = [NSString stringWithFormat:@"/api/v1/camera?bounds=%f,%f,%f,%f&limit=100", swCoord.longitude, swCoord.latitude, neCoord.longitude, neCoord.latitude];
    }
    else
    {
        urlString = [NSString stringWithFormat:@"/api/v1/camera?bounds=%f,%f,%f,%f&limit=100&fromDuration=%d", swCoord.longitude, swCoord.latitude, neCoord.longitude, neCoord.latitude,fromDuration];
    }

    _loadingCameras = YES;
    dispatch_async(dispatch_get_main_queue(), ^{
        //[_activitySpinner startAnimating];
    });

    HttpRequest* request = [HttpRequest requestWithRelativePath:urlString];
    [HttpResponse processAsynchronousRequest:request onCompletion:^(HttpResponse* response)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSMutableArray* newCameras = [[NSMutableArray alloc] init];
            newCameras = [response.responseJSON objectForKey:@"cameras"];
            for (NSDictionary* camera in newCameras)
            {
                LiveCameraAnnotation* annotation = [[LiveCameraAnnotation alloc] initWithJSON:camera];
                GMSMarker *marker = [[GMSMarker alloc] init];
                marker.position = annotation.coordinate;
                marker.title = annotation.camera.name;
                 marker.appearAnimation = kGMSMarkerAnimationPop;
                marker.icon = [GMSMarker markerImageWithColor:[UIColor purpleColor]];
                marker.userData = @{@"annotation":annotation};
                marker.map = mapView_;

                // Check if launched with camera
                if (_cameraData && [annotation.camera.uuid isEqualToString:_cameraData.uuid]){
                     [mapView_ setSelectedMarker:marker];
                    _cameraData = nil;
                }
                 marker = nil;
            }
            _loadingCameras = NO;
        });
    }];
}