How can I calculate the current zoomScale for an MKMapView?
Asked
Active
Viewed 1,236 times
2
-
Check this question http://stackoverflow.com/questions/1166444/mkmapview-zoom-and-region - may be it will help – Vladimir May 11 '11 at 15:26
-
I am actually using TroyBrant's MKMapView category to get the zoomLevel, but I also need zoomScale. – Bryan Clark May 11 '11 at 15:37
1 Answers
0
Use the following code:
#define MERCATOR_RADIUS 85445659.44705395
#define MAX_GOOGLE_LEVELS 20
- (double)getZoomLevel {
CLLocationDegrees longitudeDelta = self.mapView.region.span.longitudeDelta;
CGFloat mapWidthInPixels = self.mapView.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;
}
The return value of the getZoomLevel
method will be the current zoom level of your mapView
property.

Sujith Thankachan
- 3,508
- 2
- 20
- 25