Reputation: 434
I'm trying to extend GMSMapView to create some clustering functions and I need to detect when the user stars moving the map to disable cluster rendering and to re-enable it again when it finishes it.
I overrided touchesbegan and touchesended but touchesbegan is only called once. After overriding hittest I was able to see that GMSVectorMapView handles GMSMapView touches and if I change the return of this function the map doesn't move.
Is there any way to capture this events or to give some action when the user interacts with the map.
Best Regards, Marlon Pina Tojal
Upvotes: 7
Views: 2380
Reputation: 1532
Latest update is there is a delegate method in the Google maps
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
Upvotes: 1
Reputation: 136
I'm not sure I completely understand what touches you need to detect or why/how you need to detect them. However, I had a similar problem detecting user pan gestures on top of a GMSMapView because of touchesbegan: only being called once.
I had my own "current location" button that lets the user toggle centering the map on their location on/off. I needed to find out when the user was "panning" the map without interrupting the map's reception of the panning (I still wanted the map to pan as well).
First, I created the map:
// Creates Map centered at current location
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:theLocationManager.location.coordinate.latitude
Longitude:theLocationManager.location.coordinate.longitude
zoom:15];
theMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
theMapView.myLocationEnabled = YES;
theMapView.delegate = self;
theMapView.camera = camera;
self.view = theMapView;
Then I created a pan gesture recognizer and added it to theMapView
's gesture recognizers property. I made sure to set the target to self
with the selector method didPan:
// Watch for pan
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action:@selector(didPan:)];
theMapView.gestureRecognizers = @[panRecognizer];
Lastly, in the same main file, I implemented the didPan:
method to react when the user pans:
- (void) didPan:(UIPanGestureRecognizer*) gestureRecognizer
{
NSLog(@"DID PAN");
// React here to user's pan
}
Upvotes: 10