Created
November 21, 2013 15:33
-
-
Save xavierjurado/7583725 to your computer and use it in GitHub Desktop.
Helper function to calculate the region needed to show a number of POIs
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
// Helper function to calculate the region needed to show a number of POIs | |
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
records
must contain objects key value coding-compliant for keys "longitude" and "latitude"