Question

I am using the Google Maps iOS API. None of the delegate methods are firing. How do I make them work?

MapViewController.h:

@interface MapViewController : UIViewController <GMSMapViewDelegate>
@property (strong, nonatomic) IBOutlet GMSMapView *mapView_;

@end

#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface MapViewController ()

@end

MapViewController.m @implementation MapViewController @synthesize mapView_; GMSCircle *circ;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

// Do any additional setup after loading the view.
}

- (void)loadView {
mapView_.delegate = self;

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10
                                                        longitude:10
                                                             zoom:15];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

mapView_.mapType = kGMSTypeHybrid;

CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(10, 10);
GMSCircle *circ = [GMSCircle circleWithPosition:circleCenter
                                         radius:10];
circ.tappable = true;
[circ setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:.5]];

circ.map = self.mapView_;

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay
{
NSLog(@"in didTapOverlay");

[overlay isKindOfClass:[circ class]];
if ([overlay isKindOfClass:[circ class]]) {
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(10, 10);
        marker.title = @"Place";
        marker.snippet = @"Sub Place";
        marker.map = mapView_;

}
}


- (void) mapView:(GMSMapView *) mapView willMove:(BOOL) gesture
{
NSLog(@"In willMove");
}
@end
Was it helpful?

Solution

I think you are setting the delegate property to early

try this :

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10
                                                        longitude:10
                                                             zoom:15];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.delegate = self;
self.view = mapView_;

OTHER TIPS

Set the delegate in the ViewDidLoad

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top