Last active
          July 15, 2016 15:28 
        
      - 
      
 - 
        
Save giulio92/1cc878386d6a6a2c3bca70ca78136e1a to your computer and use it in GitHub Desktop.  
    Google Maps iOS SDK wrong GMSOverlay in didTapOverlay fix
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #import <GoogleMaps/GoogleMaps.h> | |
| @interface GMSMapView (DisableDoubleTapZoom) | |
| - (void)setDoubleTapZoomEnabled:(BOOL)enabled; | |
| @end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #import "GMSMapView+DisableDoubleTapZoom.h" | |
| @implementation GMSMapView (DisableDoubleTapZoom) | |
| - (void)setDoubleTapZoomEnabled:(BOOL)enabled { | |
| for (id view in [self subviews]) { | |
| if ([view isKindOfClass:NSClassFromString(@"GMSVectorMapView")] ) { | |
| for (UITapGestureRecognizer *rec in [view gestureRecognizers]) { | |
| NSRange range1 = [[rec description] rangeOfString:@"action=handleZoomTapGesture:"]; | |
| NSRange range2 = [[rec description] rangeOfString:@"action=handleSingleTapGesture:"]; | |
| if (range1.location && range2.location && range1.location < range2.location) { | |
| [rec setEnabled:enabled]; | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| @end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
I have noticed that if you have a lot of
GMSPolygons on yourGMSMapViewand you rely completely on Google Maps to determine if yourGMSPolygonhas been tapped or not it will (sometimes) give you the wrongGMSPolygonobject in the following delegation method:- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlayBecause every
GMSPolygonsobject has an "extra boundary" all around which helps the user select the polygon even with low levels of zoom. So if you have a lot of polygons in one restricted area (such as City regions) you will end up selecting the wrong one.With this code we loop over the
GMSMapView, looking for twoUITapGestureRecognizerwhich are responsible for this problem:and when we found them we set them disabled (instead of simply removing them which can cause compatibility issues in your
GMSMapView)There is only one thing you should keep in mind, since we disable the
handleZoomTapGesturethe user won't be able to double-tap-and-drag zoom again after you execute this code, so remember to re-enable thoseUITapGestureRecognizers at the end of the delegation method