MKMapView:如何根据Accuracy设置区域跨度?
我正在 iPhone 上实现一个地图应用程序。我希望地图放大用户当前的位置。 我想根据准确性进行放大(模拟地图应用程序的工作方式)。
我正在实现这个方法:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
我面临的问题是 CLLocation 为我提供了 HorizontalAccuracy 和 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需进行计算。只需使用 MKCooperativeRegionMakeWithDistance() 即可。
No need to do calculations. Just use
MKCoordinateRegionMakeWithDistance()
.我使用以下代码设置要在 MapView 中显示的中心和跨度。它应该有效。
I use the following code to set center and span to be shown in MapView. It should work.