Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created November 4, 2009 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeredpath/226239 to your computer and use it in GitHub Desktop.
Save lukeredpath/226239 to your computer and use it in GitHub Desktop.
#define kApproxRadiusOfEarthInMiles 3963.1676
#define kApproxSizeOfOneDegreeLatitudeInMiles 68.71
#define kApproxSizeOfOneDegreeLongitudeAtLatitude(lat) ((M_PI/180.0)* kApproxRadiusOfEarthInMiles *cos(lat))
static function MKCoordinateSpan MKCoordinateSpanMakeWithDistanceInMiles(float miles, CLLocationDegrees latitude) {
MKCoordinateSpan viewSpan;
viewSpan.latitudeDelta = miles / kApproxSizeOfOneDegreeLatitudeInMiles;
viewSpan.longitudeDelta = miles / kApproxSizeOfOneDegreeLongitudeAtLatitude(latitude);
return viewSpan;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
MKCoordinateSpan viewSpan = MKCoordinateSpanMakeWithDistanceInMiles(0.5, newLocation.coordinate.latitude);
MKCoordinateRegion viewRegion = MKCoordinateRegionMake(newLocation.coordinate, viewSpan);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
[mapView setRegion:adjustedRegion animated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment