开发者

MKMapView: How to set the region span based on the Accuracy?

开发者 https://www.devze.com 2022-12-20 02:21 出处:网络
Im implementing a map application on iPhone. I want the map to zoom in on the user\'s current location.

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.latitu开发者_C百科deDelta=.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


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


I use the following code to set center and span to be shown 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

精彩评论

暂无评论...
验证码 换一张
取 消