Drag / pan gestures in GMSMapView do not work after upgrading to SDK 1.3.1

I am having a strange problem with grabbing drag / pan gestures in GMSMapView using a gesture recognizer. This problem only occurred after upgrading from GMS 1.2 to 1.3.1, where (citing documentation ),

When using GMSMapView more aggressively consumed [/ p>

I have a UIViewController with a GMSMapView under its main view. I found that GMSMapDelegate does not provide methods for handling drag / pan gestures, so I added a UIPanGestureRecognizer to the UIViewController, linked it to the IBAction selector and set the link to the output and output assembly according to the screenshot given here: http: //i.stack .imgur.com / gktoa.png

Thus, any drag and drop action simply triggers the recognizeDragOnMap: selector, as shown below:

 -(IBAction)recognizeDragOnMap:(id)sender { NSLog(@"recognizeDragOnMap"); UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)sender; if (gestureRecognizer.state != UIGestureRecognizerStateEnded) { NSLog(@"Still dragging"); return; } NSLog(@"DragEnded"); GMSCameraPosition *position; if ((position = self.mapView.camera)) { self.automaticCameraPositionChange = NO; CLLocationCoordinate2D coordinate = [position targetAsCoordinate]; CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude]; [self.origin dragPinToLocation:location]; } else { NSLog(@"No map camera"); } } 

This setting works fine under GMS 1.2.0. After the update, GMSMapView responds to the same gestures as before, but the method above is never called!

Does anyone know what and how to fix it?

+4
source share
5 answers

For version 1.4 or higher, you just need to set consumesGesturesInView = NO in your GMSUISettings object.

If you do this, keep in mind that you will have to deal with events that can cause your supervisor to do something when you just want to interact with the map ... By this I mean, for example, that dragging and dropping a GMSMapView added to the scroll scrolls in drag mode!

+11
source
 mapView.settings.consumesGesturesInView = YES; 

Also helpful. My parent views consumed my gesture recognizer

In conjunction with

 for (UIGestureRecognizer *gestureRecognizer in mapView.gestureRecognizers) { [gestureRecognizer addTarget:self action:@selector(handlePan:)]; } ////// -(IBAction) handlePan:(UIPanGestureRecognizer*)sender { if (sender.state == UIGestureRecognizerStateEnded) { CGSize size = mapView.frame.size; CGPoint tp = CGPointMake(size.width/2, size.height/2); CLLocationCoordinate2D loc = [mapView.projection coordinateForPoint:tp]; [mapView animateToCameraPosition:[GMSCameraPosition cameraWithTarget:loc zoom:mapView.camera.zoom]]; } } 

It's great! and you don’t even need to add your own gesture recognizer.

+9
source

As it turns out, the GMSMapView instance now has a GMSBlockingGestureRecognizer that picks up all gestures. Thus, there were two options:

  • Remove this recognizer after loading the GMSMapView (possibly violating the internal functionality that depends on it) ( like this ); or
  • Attach my own target / action to the recognizer.

Following this second approach, the following code in the UIViewController viewDidLoad did everything in order:

 self.mapView = (RAMapView *)[self.view viewWithTag:1]; for (UIGestureRecognizer *gestureRecognizer in self.mapView.gestureRecognizers) { [gestureRecognizer addTarget:self action:@selector(recognizeDragOnMap:)]; } 

Honestly, this is an ugly, evil treasure, but it really works. :)

+3
source

A better alternative would be to assign a delegate to your own gesture recognizer, and then add a delegate method as follows:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 

It will continue to work.

0
source

Hi, there is a delegate method on google maps.

 - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate; 
0
source

Source: https://habr.com/ru/post/1489188/


All Articles