MKMapView:如何根据Accuracy设置区域跨度?

发布于 2024-08-21 09:05:29 字数 786 浏览 2 评论 0原文

我正在 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 (以度表示)的方法。

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

有什么想法吗?

谢谢。 贡索

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[旋木] 2024-08-28 09:05:29

无需进行计算。只需使用 MKCooperativeRegionMakeWithDistance() 即可。

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

通知家属抬走 2024-08-28 09:05:29

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

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

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]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文