-
-
Save MaciejGad/45297015683346275463 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
// returns a MKCoordinateRegion that encompasses an array of MKAnnotations | |
- (MKCoordinateRegion)regionForAnnotations:(NSArray *)annotations { | |
CLLocationDegrees minLat = 90.0; | |
CLLocationDegrees maxLat = -90.0; | |
CLLocationDegrees minLon = 180.0; | |
CLLocationDegrees maxLon = -180.0; | |
for (id <MKAnnotation> annotation in annotations) { | |
if (annotation.coordinate.latitude < minLat) { | |
minLat = annotation.coordinate.latitude; | |
} | |
if (annotation.coordinate.longitude < minLon) { | |
minLon = annotation.coordinate.longitude; | |
} | |
if (annotation.coordinate.latitude > maxLat) { | |
maxLat = annotation.coordinate.latitude; | |
} | |
if (annotation.coordinate.longitude > maxLon) { | |
maxLon = annotation.coordinate.longitude; | |
} | |
} | |
//change borders to show all annotations | |
maxLat += 0.01; | |
minLat -= 0.01; | |
maxLon += 0.01; | |
minLon -= 0.01; | |
MKCoordinateSpan span = MKCoordinateSpanMake(maxLat - minLat, maxLon - minLon); | |
CLLocationCoordinate2D center = CLLocationCoordinate2DMake((maxLat - span.latitudeDelta / 2), maxLon - span.longitudeDelta / 2); | |
return MKCoordinateRegionMake(center, span); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment