diff --git a/MKMapView+ZoomLevel.h b/MKMapView+ZoomLevel.h index c6e485f..b8b27cc 100644 --- a/MKMapView+ZoomLevel.h +++ b/MKMapView+ZoomLevel.h @@ -4,7 +4,9 @@ @interface MKMapView (ZoomLevel) - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate - zoomLevel:(NSUInteger)zoomLevel - animated:(BOOL)animated; + zoomLevel:(NSUInteger)zoomLevel + animated:(BOOL)animated; + +- (int)zoomLevel; @end diff --git a/MKMapView+ZoomLevel.m b/MKMapView+ZoomLevel.m index 2aa42a0..0eb3779 100644 --- a/MKMapView+ZoomLevel.m +++ b/MKMapView+ZoomLevel.m @@ -33,8 +33,8 @@ - (double)pixelSpaceYToLatitude:(double)pixelY #pragma mark Helper methods - (MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mapView - centerCoordinate:(CLLocationCoordinate2D)centerCoordinate - andZoomLevel:(NSUInteger)zoomLevel + centerCoordinate:(CLLocationCoordinate2D)centerCoordinate + andZoomLevel:(NSUInteger)zoomLevel { // convert center coordiate to pixel space double centerPixelX = [self longitudeToPixelSpaceX:centerCoordinate.longitude]; @@ -86,4 +86,8 @@ - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate [self setRegion:region animated:animated]; } +- (int)zoomLevel { + return (21 - round(log2(self.region.span.longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * self.bounds.size.width)))); +} + @end