4

I'm trying to overlay a UIView over a google GMSMapView. The goal is to intercept swipes in order to know when the map is being moved manually. (I know I could check -mapView:willMove: but that gets called regardless of whether the map is moving programmatically or as result of manual touch). I'm programmatically re-centering the map as the position updates--because Google doesn't do it for you like Apple does. Like every map program out there, I want to stop centering on the current position as soon as the user manually moves the map. The only way I can think to capture that occurrence (short of switching to mapkit or waiting for Google to add to the API) is to capture a swipe as it's going past a view laid over the map.

To clarify, my question is how do I lay a view over a google map, make it respond to a swipe and still allow that event to pass through to the GMSMapView?

Both my map and interceptView are sibling children of the main view. interceptView has a gestureRecognizer, is set to opaque, not hidden and userInteractionEnabled = YES. As such the interceptView picks up touch events just fine. But the map underneath doesn't move. If I set interceptView.userInteractionEnabled = NO, the map works fine.

"Passing touches" by overriding touchesBegan and calling GMSMapView's touchesBegan doesn't do anything. And overriding hitTest doesn't seem to be an option because I can't subclass GMSMapView. Has anyone done this? I know there's a lot on here about passing particular events through. I want to process a particular event on two views, one of which is Google's map layer which I can't modify the code of.

cloudsurfin
  • 2,467
  • 2
  • 25
  • 29

3 Answers3

4

mapView:willMove: receives a bool "gesture" which is true if the move was triggered by a user gesture and false if it wasn't. So you can stop re-centering the map only if "gesture" is true. That way you can be sure that the map is being moved manually.

Rai
  • 41
  • 2
  • There is one problem with this approach: It will also trigger if the user is only doing a pinch to zoom gesture. Such a gesture should not stop centering the map on the user's location. I've created a new thread for this issue: https://stackoverflow.com/questions/71752224/replicate-the-follow-my-location-mode-of-the-google-maps-app-in-a-gmsmapview – user1195883 Apr 06 '22 at 11:14
1

Here is a delegate method check it

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
SRI
  • 1,514
  • 21
  • 39
  • I used this to intercept a tap in the mapview and dimiss the View Controller. It worked well. Make sure yo implement the GMSMapViewDelegate and do mapView.delegate = self; thanks – Laurent Jan 07 '17 at 20:00
0

You can intercepte the tap using the GMSMapViewDelegete and implementing this method:

-(void)panoramaView:(GMSPanoramaView *)panoramaView didTap:(CGPoint)point;

Example:

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    CLLocationCoordinate2D panoramaNear = {latitudine,longitudine};
    GMSPanoramaView *panoView = [GMSPanoramaView panoramaWithFrame:CGRectZero
                                    nearCoordinate:panoramaNear];
    [panoView setDelegate:self];
    self.view = panoView;
}
-(void)panoramaView:(GMSPanoramaView *)panoramaView didTap:(CGPoint)point{
NSLog(@"Tap");
}
Serluca
  • 2,102
  • 2
  • 19
  • 31