Iphone – MKMapView: How to set the region span based on the Accuracy

iphonemkmapview

Im implementing a map application on iPhone. I want the map to zoom in on the user's current location.
I'd like to zoom closer based on the accuracy (emulating how the Maps app works).

Im implementing this method:

    - (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
fromLocation:(CLLocation *)oldLocation {

The problem I face is that CLLocation provides me the accuracy with the properties horizontalAccuracy and verticalAccuracy, that in the end means meters. However, to center the map I using this:

MKCoordinateRegion region;
MKCoordinateSpan span;
region.center = newLocation.coordinate; 
span.latitudeDelta=.005;  //THIS IS HARDCODED
span.longitudeDelta=.005; //THIS IS HARDCODED   
region.span = span;

[mapView setRegion:region animated:YES];

Im looking for a way to calculate the latitudeDelta (represented in degrees) based on the horizontalAccuracy (represented in meters).

It doesn't need to be a exact conversion (Im not looking forward a conversion formula, that will require quite some calculation, including the current location), just some aprox values.

Any ideas?

Thanks.
Gonso

Best Answer

No need to do calculations. Just use MKCoordinateRegionMakeWithDistance().

Related Topic