Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find current zoom level of MKMapView?

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?

like image 347
Chatar Veer Suthar Avatar asked Sep 29 '11 08:09

Chatar Veer Suthar


People also ask

What is MKMapView?

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.

How do you zoom map in react native?

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.


1 Answers

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 
like image 176
NiKe Avatar answered Sep 17 '22 20:09

NiKe