Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions MKMapView+ZoomLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions MKMapView+ZoomLevel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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