Search code examples
google-maps-sdk-ios

Zoom without changing Camera center


I have a GMSMapView which is centred around User's GPS location.

When the user double taps, the map's centre shifts to the touched location, instead I just want the map to zoom without changing the Camera location!

Went through the docs, unable to figure out how I can achieve this.


Solution

  • Finally found the answer myself by digging into their source code as its not mentioned anywhere in the docs!

    This particular behaviour(zoom without changing camera centre) is a config item called, allowScrollGesturesDuringRotateOrZoom (who would've guessed!) in GMSUISettings class, so you can access it on your GMSMapView object's 'settings' property like below,

    Obj-C:

    mapView.settings.allowScrollGesturesDuringRotateOrZoom = NO;
    

    Swift 2.1:

    mapView.settings.allowScrollGesturesDuringRotateOrZoom = false
    

    Now on zoom (double tap / pinch), the scroll won't happen, effectively keeping the camera view unchanged!