Created
July 3, 2014 15:12
-
-
Save d2burke/ad29811b07ae31b378ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MKMapView+ZoomLevel.m | |
// | |
// Created by Daniel.Burke on 7/3/14 via Nikita Galayko @ StackOverflow | |
// Copyright (c) 2014 Forrent.com. All rights reserved. | |
// | |
#import "MKMapView+ZoomLevel.h" | |
@implementation MKMapView (ZoomLevel) | |
- (double)zoomLevel{ | |
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; | |
return zoomer; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MKMapView+ZoomLevel.h | |
// | |
// Created by Daniel.Burke on 7/3/14 via Nikita Galayko @ StackOverflow | |
// Copyright (c) 2014 Forrent.com. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#define MERCATOR_RADIUS 85445659.44705395 | |
#define MAX_GOOGLE_LEVELS 20 | |
@import UIKit; | |
@interface MKMapView (ZoomLevel) | |
- (double)zoomLevel; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment