Google Maps iOS SDK 1.6.1.6332 subviews not recognizing gesture recognizers

By: Kevin | January 7, 2014

I was recently working on a project that included Google Maps iOS SDK. I was adding custom UIViews to the map and wanted to have other custom animations with different gesture recognizers. I ran into an issue that none of my gesture recognizers were firing, after a day of pounding my head it came down to a pretty simple change.

Below is the sample code provided on the main page of the Google Maps SDK for iOS page. The code below will successfully display a map however for some reason when you use the below snippet adding subviews is a no go!

#import <GoogleMaps/GoogleMaps.h>
#import "DemoViewController.h"

@implementation DemoViewController

- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:6];

//Notice the "CGRectZero"
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = @"Hello World";
marker.animated = YES;

//And this
self.view = mapView;
}

@end

 

With two minor tweaks (noted) I got the behavior I wanted. Just manually change the frame of the map and add the map as a subview of the UIViewControllers view instead of assigning it as the view. Thats it, does the trick!

#import <GoogleMaps/GoogleMaps.h>
#import "DemoViewController.h"

@implementation DemoViewController

- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:6];

/*Here I set the frame manually*/
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) camera:camera];

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = @"Hello World";
marker.animated = YES;

/*Now I add the map as a subview*/
[self.view addSubview:self.map];
}
@end

Hope this helps someone else. Cheers!