MKCoordinateRegion中心和边界之间的距离 [英] MKCoordinateRegion distance between center and borders

查看:160
本文介绍了MKCoordinateRegion中心和边界之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(基于评论的修订问题:)

好的,我将尝试以其他方式询问...如何获取该圆形叠加层的边界坐标:

OK I will try to ask in other way...How can I get border coordinates of this circle overlay:


(原始问题:)

我的iPhone应用程序有奇怪的问题.我有MKCoordinateRegion,其中心坐标纬度:51.509980和经度:-0.133700.我使用了MKCoordinateRegionMakeWithDistance方法,并将距离设置为16,093.44米(10英里).

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

我找到该网站进行测试 http://boulter.com/gps/distance/计算两个坐标之间的距离.当我输入FROM坐标:51.509980和经度:-0.133700(伦敦)和TO坐标:

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

我得到这两个坐标之间的距离是15.40英里,而不是预期的10英里.

I get that the distance between those two coordinates is 15.40 miles instead of expected 10 miles.

屏幕截图:

为什么会有这样的区别?当我尝试执行相同的操作但从不同的中心坐标(东京,纽约)出发时,结果是正确的10英里.

Why such a difference? When I tried to do the same but from different center coordinates (Tokyo, New York) result were correct 10 miles.

感谢您的回复

推荐答案

(基于评论的修订答案:)

如果您要获取该圆形叠加层的边界矩形的坐标,请使用叠加层的boundingMapRect属性:

If you mean you want the coordinates of the bounding rectangle for that circle overlay, use the overlay's boundingMapRect property:

//"theCircle" is the MKCircle overlay object

CLLocationCoordinate2D topLeftCoord = 
    MKCoordinateForMapPoint(theCircle.boundingMapRect.origin);

MKMapPoint bottomRightMapPoint = MKMapPointMake (
    MKMapRectGetMaxX(theCircle.boundingMapRect), 
    MKMapRectGetMaxY(theCircle.boundingMapRect));

CLLocationCoordinate2D bottomRightCoord = 
    MKCoordinateForMapPoint(bottomRightMapPoint);


(原始答案:)

首先,当您在地图视图上调用setRegion时,地图视图几乎总是会修改您请求的区域,以使其适合地图视图.此调整基于地图视图的形状以及它是否可以在其固定缩放级别之一下正确显示请求的跨度.

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.

例如,如果您的地图视图不是正方形,并且您要求两个方向的跨度均为10英里,则肯定会至少调整一个跨度.即使您要求根据视图的比例设置跨度,但如果地图视图无法显示该缩放级别的图块(或者如果您未使用地球的缩放比例),它仍可能会被调整.曲率).

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).

接下来,latitudeDeltalongitudeDelta定义区域的整个高度和宽度(不是距中心坐标的距离).

Next, the latitudeDelta and longitudeDelta define the entire height and width of the region (not the distance from the center coordinate).

因此,无法将屏幕截图中的测试与跨度增量进行比较.在屏幕截图中,您正在计算从中心坐标到最小纬度和经度(左下角)的距离,但是跨度增量从右到左,从下到上一直到最远. (因此,您认为从中心到拐角的距离应小于增量,而不是增量.该距离较短,但由于上述原因,增量也已增加到10以上.)

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:

CLLocationCoordinate2D bottomLeftCoord = 
    [myMapView convertPoint:CGPointMake(0, myMapView.frame.size.height) 
               toCoordinateFromView:myMapView];

CLLocationCoordinate2D topRightCoord = 
    [myMapView convertPoint:CGPointMake(myMapView.frame.size.width, 0) 
               toCoordinateFromView:myMapView];

这篇关于MKCoordinateRegion中心和边界之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆