Doc
Doc

Reputation: 57

iPhone: Get Selected zoom level of Google map

We need to get the current selected zoom level of MKMapView when user either zooms-in or zooms-out on the Google Maps using Mapkit.

The solution we have tried is running fine on simulator but not on real device (iPhone 3GS having iOS 3.0.1). We need to get it running on iOS 3+ (including iOS 4)

Following is the code we are using to get the zoom-level:-

On zoom-in/out, Mapkit calls this delegate:-

(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

which in turns calls our Mapzoomlevel function:-

#define MERCATOR_RADIUS 85445659.44705395

-(float) Mapzoomlevel {
  return 21 - round(log2(_mapView.region.span.longitudeDelta *
    MERCATOR_RADIUS * M_PI / (180.0 * _mapView.bounds.size.width)));
}

This code was taken from (see get zoom level example first comment posted on this blog):-

http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/

Upvotes: 2

Views: 4025

Answers (1)

johndpope
johndpope

Reputation: 5257

https://github.com/jdp-global/MKMapViewZoom

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    int zoomLevel = [mapView zoomLevel];

}

Upvotes: 5

Related Questions