Created
May 5, 2010 18:13
-
-
Save afarnham/391205 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
MKCoordinateRegion region; | |
if ([locations count] > 0) { | |
CLLocation *firstLoc = [locations objectAtIndex:0]; | |
CLLocationCoordinate2D southWest = firstCoord.coordinate; | |
CLLocationCoordinate2D northEast = southWest; | |
for (CLLocation* loc in founds) { | |
southWest.latitude = MIN(southWest.latitude, loc.coordinate.latitude); | |
southWest.longitude = MIN(southWest.longitude, loc.coordinate.longitude); | |
northEast.latitude = MAX(northEast.latitude, loc.coordinate.latitude); | |
northEast.longitude = MAX(northEast.longitude, loc.coordinate.longitude); | |
} | |
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude]; | |
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude]; | |
// This is a diag distance (if you wanted tighter you could do NE-NW or NE-SE) | |
CLLocationDistance meters = [locSouthWest getDistanceFrom:locNorthEast]; | |
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0; | |
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0; | |
region.span.latitudeDelta = meters / 111319.5; | |
region.span.longitudeDelta = 0.0; | |
[locSouthWest release]; | |
[locNorthEast release]; | |
} else { | |
region.center.latitude = DEFAULT_LAT; | |
region.center.longitude = DEFAULT_LONG; | |
region.span.latitudeDelta = 0.1; | |
region.span.longitudeDelta = 0.1; | |
} | |
self.mapView.region = [self.mapView regionThatFits:region]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment