Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 419
Idan Moshe Avatar asked Sep 28 '13 11:09

Idan Moshe


3 Answers

In release 1.9.2 there is a delegate method that does exactly that:

(BOOL) didTapMyLocationButtonForMapView: (GMSMapView *) mapView [optional]

Link to documentation

like image 103
UpCat Avatar answered Oct 21 '22 14:10

UpCat


Delegate method available

func didTapMyLocationButton(for mapView: GMSMapView) -> Bool{

}
like image 2
Devendra Singh Avatar answered Oct 21 '22 14:10

Devendra Singh


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.

like image 1
tony m Avatar answered Oct 21 '22 15:10

tony m