I'm using google maps SDK 1.7.2 on a projectd using iOS 7 (I just upgraded it from iOS6). For some reason all the GMSMapViewDelegate callbacks work but this one
- (BOOL) didTapMyLocationButtonForMapView: (GMSMapView *)mapView
I'm assuming this should be called when the arrow button is tapped right? Any idea why it isn't?
This is how I instantiate the mapsview:
mapView_ = [GMSMapView mapWithFrame:[[self mainView] bounds]
camera:[self currentCameraUseStandartZoom:YES]];
[[mapView_ settings] setMyLocationButton:YES];
[mapView_ setDelegate:self];
[[self mainView] addSubview:mapView_];
just in case someone is having the same problem.. i pretty much resolved this by using a hack.. here it is:
in my main.m file I customized the UIResponder
class:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, NSStringFromClass([TPMUApplication class]), NSStringFromClass([TPMUAppDelegate class]));
}
}
TPMUApplication.h
#import <UIKit/UIKit.h>
@class TPMUTaxiRequestVC;
@interface TPMUApplication : UIApplication
// basically the view controller that will be informed that
// the user has tapped the my location button, normally it would subscribe to
// the GMSMapViewDelegate protocol, and it should have a GMSMapView property
@property (nonatomic, strong) TPMUTaxiRequestVC *taxiRequestVC;
@end
TPMUApplication.m
#import "TPMUApplication.h"
#import "TPMUTaxiRequestVC.h"
@implementation TPMUApplication
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
UIView *touchReceipientView =((UITouch *)[event.allTouches anyObject]).view;
NSLog(@"");
CGRect myLocationButtonFourchIncFrame = CGRectMake(256, 525, 64, 54);
CGRect myLocationButtonThreeHalfIncFrame = CGRectMake(256, 336, 64, 54);
if (CGRectEqualToRect(touchReceipientView.frame, myLocationButtonFourchIncFrame) ||
CGRectEqualToRect(touchReceipientView.frame, myLocationButtonThreeHalfIncFrame)) {
if (self.taxiRequestVC.mapState != TPMUMapStateInMotionAsResultOfMyLocationButtonTap) {
self.taxiRequestVC.mapState = TPMUMapStateInMotionAsResultOfMyLocationButtonTap;
// notice that didTapMyLocationButtonForMapView is actually
// a method in the GMSMapViewDelegate protocol.. and since
// taxiRequestVC subscribes to that protocol.. we simply call it here
// as if it was natively called
[self.taxiRequestVC didTapMyLocationButtonForMapView:self.taxiRequestVC.mapView];
}
}
}
@end
and just in case you were wondering, TPMUMapStateInMotionAsResultOfMyLocationButtonTap
is a state of a state machine variable with the following states:
typedef enum
{
TPMUMapStateIdle = 0,
TPMUMapStateInMotionAsResultOfUserGesture,
TPMUMapStateInMotionAsResultOfMyLocationButtonTap
} TPMUMapState;
since I wanted to track motion in the map as a result of location button tap vs user gesture.
hope this helps!