I want to know the current zoom level of MKMapView
in iphone programming, how can I do that? Actually I have one app, that is taking few arguments(Radius from center to corner of MKMapView
) are returning the store details in that are, when I am on MKMapView
, the radius is very high and it changes when Radius is smaller, so I want to know the zoom level and setup my webservice according to that, How can I get zoom level of current MKMapView
visible area?
The MKMapView class supports the ability to annotate the map with custom information. Because a map may have large numbers of annotations, map views differentiate between the annotation objects used to manage the annotation data and the view objects for presenting that data on the map.
It takes a region object which has latitudeDelta and longitudeDelta . Use these to set the zoom level. Updated: in a Region object the latitude and longitude specify the center location and latitudeDelta and longitudeDelta specify the span of the viewable map area.
I created very simple helper subclass for it:
#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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With