Search code examples
iosobjective-ciphonecocoa-touchgoogle-maps-sdk-ios

Change GMSCameraPosition zoom (iOS)


I want to change GMSCameraPosition' zoom programmatically (Google Maps iOS SDK).

I tried to change:

mapView.Camera.Zoom=11;

but it's a "read-only" property and "setZoom:" does not exist.

How can I do that?


Solution

  • There is different way to do that.

    You can use -animateToZoom: on your GMSMapView, or you can create a GMSCameraPosition and set the coordinate and zoom level and then use -animateToCameraPosition: or create a GMSCameraUpdate and then use -animateWithCameraUpdate:

    GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithLatitude:latitude
                                                                    longitude:longitude
                                                                         zoom:11.0];
    
    [self.mapView animateToCameraPosition:cameraPosition];
    

    or

    GMSCameraUpdate *update = [GMSCameraUpdate zoomTo:11.0];
    [self.mapView animateWithCameraUpdate:update];
    

    or

    [self.mapView animateToZoom:11.0];
    

    Hope it helps.