Created
February 1, 2013 10:51
-
-
Save rais38/4690624 to your computer and use it in GitHub Desktop.
Calculate the region needed to show a number of POIs in MKMapView
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
/** | |
MKCoordinateRegion viewRegion = [self RegionForAnnotations:_arrayPois]; | |
[_mapView setRegion:viewRegion animated:YES]; | |
*/ | |
- (MKCoordinateRegion)RegionForAnnotations:(NSArray *)records { | |
MKCoordinateRegion region; | |
// center the map arround our records | |
// @see https://devforums.apple.com/message/48525#48525 | |
double minLatitude = [[records valueForKeyPath:@"@min.latitude"] doubleValue]; | |
double maxLatitude = [[records valueForKeyPath:@"@max.latitude"] doubleValue]; | |
double minLongitude = [[records valueForKeyPath:@"@min.longitude"] doubleValue]; | |
double maxLongitude = [[records valueForKeyPath:@"@max.longitude"] doubleValue]; | |
region.center.latitude = (maxLatitude - minLatitude)/2.0 + minLatitude; | |
region.center.longitude = (maxLongitude - minLongitude)/2.0 + minLongitude; | |
region.span.latitudeDelta = (maxLatitude - minLatitude); | |
region.span.longitudeDelta = (maxLongitude - minLongitude); | |
region.span.latitudeDelta = MAX (region.span.latitudeDelta, 0.03); | |
region.span.longitudeDelta = MAX (region.span.longitudeDelta, 0.03); | |
return region; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment