4

我在 iPhone 上实现了一个地图应用程序。我希望地图放大用户的当前位置。我想根据准确性(模拟地图应用程序的工作方式)拉近一点。

我实现了这个方法:

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

我面临的问题是 CLLocation 通过属性 Horizo​​ntalAccuracy 和 VerticalAccuracy 为我提供了精度,这最终意味着米。但是,为了使地图居中,我使用以下方法:

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];

我正在寻找一种基于水平精度(以米表示)计算 latitudeDelta(以度表示)的方法。

它不需要是一个精确的转换(我不期待一个转换公式,这将需要相当多的计算,包括当前位置),只是一些近似值。

有任何想法吗?

谢谢。贡索

4

2 回答 2

13

无需进行计算。只需使用MKCoordinateRegionMakeWithDistance().

于 2010-02-11T19:08:44.713 回答
0

我使用以下代码设置要在 MapView 中显示的中心和跨度。它应该工作。

MKCoordinateRegion region = {{0,0},{.5,.5}}; 
region.center.latitude = doubleLattitude; //user defined
region.center.longitude = doubleLongitude;//user defined
[mapView setRegion:region animated:YES]; 
于 2012-06-22T12:53:51.110 回答