Idan Moshe Idan Moshe - 16 days ago 5
iOS Question

Trigger when 'myLocation' button tapped (Google Maps SDK for iOS)

I want to do some stuff when 'myLocation' button tapped.
So far, I've the

UIButton
itself:

UIButton *btnMyLoc = (UIButton*)[self.googleMapView subviews].lastObject;


But it's not enough.
Any ideas?

Answer

Currently there is no direct method in Google Maps IOS sdk for knowing when the user taps on MyLocation button. A possible workaround is to use the below method

- (void) mapView: (GMSMapView *) mapView  idleAtCameraPosition: (GMSCameraPosition *)   position 

This will be called at the end of any camera animation or gestures. When a user clicks mylocation button, the camera will be animated to position the visible map region such that the user's current location(if detected) will lie at the center. So you can check inside idleAtCameraPosition whether the location is same as the user's current location that can be known through - (CLLocation*) myLocation [read, assign] and do your required functionality.

Comments