Last active
December 11, 2015 16:18
-
-
Save fmundaca/4626559 to your computer and use it in GitHub Desktop.
This file contains 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
#define MINIMUM_ZOOM_ARC 0.003 //approximately 1 miles (1 degree of arc ~= 69 miles) | |
#define ANNOTATION_REGION_PAD_FACTOR 1.1 | |
#define MAX_DEGREES_ARC 360 | |
+(MKCoordinateRegion)adjustZoomMapView:(NSArray*) locations { | |
int count = [locations count]; | |
MKMapPoint points[count]; //C array of MKMapPoint struct | |
for( int i=0; i<count; i++ ) //load points C array by converting coordinates to points | |
{ | |
CLLocationCoordinate2D *point = [locations objectAtIndex:i]; | |
points[i] = MKMapPointForCoordinate(coordinate); | |
} | |
MKMapRect mapRect = [[MKPolygon polygonWithPoints:points count:count] boundingMapRect]; | |
MKCoordinateRegion region = MKCoordinateRegionForMapRect(mapRect); | |
region.span.latitudeDelta *= ANNOTATION_REGION_PAD_FACTOR; | |
region.span.longitudeDelta *= ANNOTATION_REGION_PAD_FACTOR; | |
if( region.span.latitudeDelta > MAX_DEGREES_ARC ) { region.span.latitudeDelta = MAX_DEGREES_ARC; } | |
if( region.span.longitudeDelta > MAX_DEGREES_ARC ){ region.span.longitudeDelta = MAX_DEGREES_ARC; } | |
if( region.span.latitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.latitudeDelta = MINIMUM_ZOOM_ARC; } | |
if( region.span.longitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.longitudeDelta = MINIMUM_ZOOM_ARC; } | |
return region; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment