Guest User

Untitled

a guest
Apr 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #define kApproxRadiusOfEarthInMiles 3963.1676
  2. #define kApproxSizeOfOneDegreeLatitudeInMiles 68.71
  3. #define kApproxSizeOfOneDegreeLongitudeAtLatitude(lat) ((M_PI/180.0)* kApproxRadiusOfEarthInMiles *cos(lat))
  4.  
  5. static function MKCoordinateSpan MKCoordinateSpanMakeWithDistanceInMiles(float miles, CLLocationDegrees latitude) {
  6. MKCoordinateSpan viewSpan;
  7. viewSpan.latitudeDelta = miles / kApproxSizeOfOneDegreeLatitudeInMiles;
  8. viewSpan.longitudeDelta = miles / kApproxSizeOfOneDegreeLongitudeAtLatitude(latitude);
  9. return viewSpan;
  10. }
  11.  
  12. - (void)locationManager:(CLLocationManager *)manager
  13. didUpdateToLocation:(CLLocation *)newLocation
  14. fromLocation:(CLLocation *)oldLocation {
  15.  
  16. MKCoordinateSpan viewSpan = MKCoordinateSpanMakeWithDistanceInMiles(0.5, newLocation.coordinate.latitude);
  17. MKCoordinateRegion viewRegion = MKCoordinateRegionMake(newLocation.coordinate, viewSpan);
  18.  
  19. MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
  20. [mapView setRegion:adjustedRegion animated:YES];
  21. }
Add Comment
Please, Sign In to add comment