Created
September 25, 2013 00:54
-
-
Save aaronpk/6693579 to your computer and use it in GitHub Desktop.
Center a MKMapView given a GeoJSON bounding box
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
double lng1 = [bbox[0] doubleValue]; | |
double lat1 = [bbox[1] doubleValue]; | |
double lng2 = [bbox[2] doubleValue]; | |
double lat2 = [bbox[3] doubleValue]; | |
MKCoordinateSpan span; | |
span.latitudeDelta = fabs(lat2 - lat1); | |
span.longitudeDelta = fabs(lng2 - lng1); | |
CLLocationCoordinate2D center; | |
center.latitude = fmax(lat1, lat2) - (span.latitudeDelta / 2.0); | |
center.longitude = fmax(lng1, lng2) - (span.longitudeDelta / 2.0); | |
MKCoordinateRegion region; | |
region.span = span; | |
region.center = center; | |
[self.mapView setRegion:region animated:NO]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, just ran across this while working on a project. I need to go the opposite direction, but this was a nice help. Thanks Aaron!