amar
amar

Reputation: 185

marker is not showing on google map

I am using GoogleMap SDK in iOS to display user's current location. Google map is showing on my view but marker is not visible. I don't know what I am doing wrong here.

Here is my code

#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_;
 }

Upvotes: 0

Views: 3255

Answers (2)

John Russel Usi
John Russel Usi

Reputation: 453

Why are you setting your map with CGRectZero frame??

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

The map will not be visible if you set it's frame to CGRectZero. So first, try making your mapView visible by giving it a different frame.

Upvotes: 2

Mihir Oza
Mihir Oza

Reputation: 2796

I don't no where is the issue but I think this method helps you which I implemented in my app.

- (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;
        });
    }];
}

Upvotes: 0

Related Questions