1

Hello I want to get current zoom level of Google Map view, like in a condition to check. For example,

if(mapView.zoom==18.0)
{
 //code goes here..
}

How to get that ?

iOSNoob
  • 1,420
  • 2
  • 16
  • 30

2 Answers2

35

It's pretty easy. GMSMapView has a camera (GMSCameraPosition) property that has a zoom property.

CGFloat zoom = mapView.camera.zoom;

Note that zoom property is readonly.

NKorotkov
  • 3,591
  • 1
  • 24
  • 38
1

You can use below code.

#define MERCATOR_RADIUS 85445659.44705395
#define MAX_GOOGLE_LEVELS 20

@interface MKMapView (ZoomLevel)
- (double)getZoomLevel;
@end

@implementation MKMapView (ZoomLevel)

- (double)getZoomLevel
{
    CLLocationDegrees longitudeDelta = self.region.span.longitudeDelta;
    CGFloat mapWidthInPixels = self.bounds.size.width;
    double zoomScale = longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * mapWidthInPixels);
    double zoomer = MAX_GOOGLE_LEVELS - log2( zoomScale );
    if ( zoomer < 0 ) zoomer = 0;
//  zoomer = round(zoomer);
    return zoomer;
}

@end

Also can use MKCoordinateSpan check document for more information.

typedef struct {
    CLLocationDegrees latitudeDelta;
    CLLocationDegrees longitudeDelta;
} MKCoordinateSpan;
Dipen Patel
  • 911
  • 2
  • 9
  • 22
  • There is also third party class available https://github.com/warmshowers/warmshowers-iphone-app/blob/master/Classes/MKMapView%2BZoomLevel.m – Dipen Patel Feb 04 '15 at 07:22
  • Code contains all about MKMapView ! Does this work for Google Map View also ? I wonder. – iOSNoob Feb 04 '15 at 07:22
  • 1
    For google map you can use GMSCameraPosition to get zoom level. Have a look on https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_camera_position – Dipen Patel Feb 04 '15 at 07:23
  • 3
    CGFloat currentZoom = self.MapView.camera.zoom; – Dipen Patel Feb 04 '15 at 07:25
  • Can you please accept the answer if it works for you so other can also get idea from this post. – Dipen Patel Feb 04 '15 at 07:26