Reputation: 1533
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?
Upvotes: 6
Views: 7352
Reputation: 573
func didTapMyLocationButton(for mapView: GMSMapView) -> Bool {
//if want to change the camera position
if self.latDouble != 0.0 && self.longDouble != 0.0
{
let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: self.latDouble, longitude: self.longDouble, zoom: 18.0)
self.mapView.camera = camera
}
self.mapView.isMyLocationEnabled = true
self.mapView.reloadInputViews()
return true
}
Upvotes: 0
Reputation: 777
Delegate method available
func didTapMyLocationButton(for mapView: GMSMapView) -> Bool{
}
Upvotes: 2
Reputation: 70466
In release 1.9.2 there is a delegate method that does exactly that:
(BOOL) didTapMyLocationButtonForMapView: (GMSMapView *) mapView [optional]
Upvotes: 19
Reputation: 2036
For do any thing other you also can get reference to Location Button.
// custom target My Location Button
for (UIView* tmpview in _mapView.subviews[1].subviews[0].subviews) {
if ([NSStringFromClass([[tmpview class] class]) isEqualToString:@"GMSx_QTMButton"]) {
if ([tmpview isKindOfClass:[UIButton class]]) {
myLocationBtn = (UIButton*)tmpview;
[myLocationBtn addTarget:self action:@selector(clickedOnLocationButton:) forControlEvents:UIControlEventTouchUpInside];
}
}
}
Upvotes: 0
Reputation: 4779
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.
Upvotes: 1