MKMapView: how to set range of areas based on accuracy?

Im implements a map application on an iPhone. I want the map closer to the user's current location. I would like to zoom in on the accuracy (emulating how the Maps application works).

Im implements this method:

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

The problem I am facing is that CLLocation gives me accuracy with the horizontalAccuracy and verticalAccuracy properties, which in the end means meters. However, to center the map, I use 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 latitudeDelta (represented in degrees) based on horizontal accuracy (represented in meters).

It does not have to be an exact conversion (Im not expecting a conversion formula that will require quite some calculation, including the current location), only some aprox values.

Any ideas?

Thanks. Gonso

+4
source share
2 answers

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

+12
source

I use the following code to set the center and range to display in MapView. It should work.

 MKCoordinateRegion region = {{0,0},{.5,.5}}; region.center.latitude = doubleLattitude; //user defined region.center.longitude = doubleLongitude;//user defined [mapView setRegion:region animated:YES]; 
0
source

Source: https://habr.com/ru/post/1301032/


All Articles