MKCoordinateRegion 中心与边框之间的距离
(根据评论修改问题:)
好的,我会尝试以其他方式询问...我怎样才能获得此圆圈叠加层的边框坐标:
(Original Question:)
我的 iPhone 应用程序遇到奇怪的问题。我有 MKCooperativeRegion ,其中心坐标纬度:51.509980 和经度:-0.133700。我使用了方法 MKCooperativeRegionMakeWithDistance 并将距离设置为 16,093.44 米(10 英里)。
我想获得这个区域的边界点,因此我有这个代码:
MKCoordinateRegion region2 = self.myMapView.region;
float minLat = region2.center.latitude - (region2.span.latitudeDelta / 2.0);
float maxLat = region2.center.latitude + (region2.span.latitudeDelta / 2.0);
float minLong = region2.center.longitude - (region2.span.longitudeDelta / 2.0);
float maxLong = region2.center.longitude + (region2.span.longitudeDelta / 2.0);
我找到这个网站进行测试 http:// /boulter.com/gps/distance/ 计算两个坐标之间的距离。当我输入 FROM 坐标:51.509980 和经度:-0.133700(伦敦)和 TO 坐标:时
2011-11-26 01:15:42.830 NearMeTest[3911:11603] MinLAT 51.334381 and MaxLAT 51.684814
2011-11-26 01:15:42.830 NearMeTest[3911:11603] MinLONG -0.352936 and MaxLONG 0.086517
,我发现这两个坐标之间的距离是 15.40 英里,而不是预期的 10 英里。
屏幕截图:
为什么会有这样的差异?当我尝试做同样的事情但从不同的中心坐标(东京,纽约)结果是正确的 10 英里。
感谢您的回复
(Revised Question based on comment:)
OK I will try to ask in other way...How can I get border coordinates of this circle overlay:
(Original Question:)
I am having weird problem with my iPhone app. I have MKCoordinateRegion which has center coordinate latitude: 51.509980 and longitude: -0.133700. I have used method MKCoordinateRegionMakeWithDistance and set the distance to be 16,093.44 meters (10 miles).
I want to get border point of this region therefore I have this code:
MKCoordinateRegion region2 = self.myMapView.region;
float minLat = region2.center.latitude - (region2.span.latitudeDelta / 2.0);
float maxLat = region2.center.latitude + (region2.span.latitudeDelta / 2.0);
float minLong = region2.center.longitude - (region2.span.longitudeDelta / 2.0);
float maxLong = region2.center.longitude + (region2.span.longitudeDelta / 2.0);
I found this website for my testing http://boulter.com/gps/distance/ which calculates distance between two coordinates. When I enter as a FROM coordinate: 51.509980 and longitude: -0.133700 (London) and TO coordinate:
2011-11-26 01:15:42.830 NearMeTest[3911:11603] MinLAT 51.334381 and MaxLAT 51.684814
2011-11-26 01:15:42.830 NearMeTest[3911:11603] MinLONG -0.352936 and MaxLONG 0.086517
I get that the distance between those two coordinates is 15.40 miles instead of expected 10 miles.
Screenshot:
Why such a difference? When I tried to do the same but from different center coordinates (Tokyo, New York) result were correct 10 miles.
Thanks for reply
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(根据评论修改答案:)
如果您想要该圆形叠加层的边界矩形的坐标,请使用叠加层的
boundingMapRect
属性:(Original Answer:)
首先,当您在地图视图上调用
setRegion
时,地图视图几乎总是会修改您请求的区域,以使其适合地图视图。此调整基于地图视图的形状以及它是否可以在其固定缩放级别之一正确显示所请求的跨度。例如,如果您的地图视图不是方形的,并且您要求两个方向的跨度均为 10 英里,那么至少其中一个跨度肯定要进行调整。即使您要求根据视图的比例设置跨度,如果地图视图无法显示该缩放级别的图块(或者如果您没有采用地球的缩放比例),它仍然可以进行调整。考虑曲率)。
接下来,
latitudeDelta
和longitudeDelta
定义区域的整个高度和宽度(不是到中心坐标的距离)。因此,您在屏幕截图中的测试无法与跨度增量进行比较。在屏幕截图中,您正在计算从中心坐标到最小纬度和经度(左下角)的距离,但跨度增量是从右到左、从下到上的。 (因此,您可能会认为从中心到角点的距离应该小于 Delta,而不是更多。它更短,但由于上述原因,Delta 也增加到了 10 以上。)
最后,要获取角坐标(左下角和右上角),这可能是更准确的方法:
(Revised Answer based on comment:)
If you mean you want the coordinates of the bounding rectangle for that circle overlay, use the overlay's
boundingMapRect
property:(Original Answer:)
First, when you call
setRegion
on the map view, the map view will almost always modify the region you requested so that it fits in the map view. This adjustment is based on the shape of the map view and whether it can show the requested span properly at one of its fixed zoom levels.For example, if your map view is not square and you ask for a span of 10 miles in both directions, at least one of the spans is definitely going to be adjusted. Even if you ask for a span that you've set based on the proportions of the view, it could still get adjusted if the map view can't show the tiles at that zoom level (or perhaps if you've not taken the Earth's curvature into account).
Next, the
latitudeDelta
andlongitudeDelta
define the entire height and width of the region (not the distance from the center coordinate).So your test in the screenshot cannot be compared with the span delta. In the screenshot, you are calculating the distance from the center coordinate to the minimum latitude and longitude (bottom-left corner) but the span deltas go all the way from right to left and bottom to top. (Because of that, you'd think that the distance from the center to a corner should be less than the delta--not more. It is shorter but the delta has also increased to more than 10 because of the reasons described above.)
Finally, to get the corner coordinates (bottom-left and top-right), this is probably a more accurate way to do it:
在网络表单的屏幕截图中,您会得到不同的距离,因为您正在测量的线(中心到 MinLAT / MinLONG)是对角线并且延伸超出了圆半径。
如果您遵循@AnnaKarenina的答案,则可以通过将每个
CLLocationCooperative2D
转换为CLLocation
来获取以米为单位的距离。以下是获取以英里为单位的半径的方法:
In your screenshot of the web form, you're getting a different distance because the line you're measuring (center to MinLAT / MinLONG) is diagonal and extends beyond the circle radius.
If you follow @AnnaKarenina's answer, you can then get the distance in meters by converting each
CLLocationCoordinate2D
into aCLLocation
.Here's how you'd get the radius in miles: