Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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];
- }
Add Comment
Please, Sign In to add comment