4

(根据评论修改问题:)

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

在此处输入图像描述


(原问题:)

我的 iPhone 应用程序出现奇怪的问题。我有 MKCoordinateRegion,它的中心坐标纬度:51.509980 和经度:-0.133700。我使用了方法 MKCoordinateRegionMakeWithDistance 并将距离设置为 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 英里。

谢谢您的回复

4

2 回答 2

3

(根据评论修改答案:)

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

//"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地图视图时,地图视图几乎总是会修改您请求的区域以使其适合地图视图。此调整基于地图视图的形状以及它是否可以在其固定缩放级别之一正确显示请求的跨度。

例如,如果您的地图视图不是方形的,并且您要求双向跨度为 10 英里,那么肯定会调整至少一个跨度。即使您要求根据视图比例设置的跨度,如果地图视图无法以该缩放级别显示图块(或者如果您没有使用地球的曲率考虑)。

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

因此,您在屏幕截图中的测试无法与跨度增量进行比较。在屏幕截图中,您正在计算从中心坐标到最小纬度和经度(左下角)的距离,但跨度增量从右到左和从下到上一直延伸。(正因为如此,你会认为从中心到角落的距离应该小于 delta——而不是更多。它更短,但由于上述原因,delta 也增加到了 10 以上。)

最后,要获得角坐标(左下角和右上角),这可能是一种更准确的方法:

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

CLLocationCoordinate2D topRightCoord = 
    [myMapView convertPoint:CGPointMake(myMapView.frame.size.width, 0) 
               toCoordinateFromView:myMapView];
于 2011-11-26T04:30:33.140 回答
0

在 Web 表单的屏幕截图中,您得到的距离不同,因为您测量的线(中心到 MinLAT / MinLONG)是对角线并且延伸到圆半径之外。

如果您遵循@AnnaKarenina 的回答,则可以通过将每个CLLocationCoordinate2D转换为CLLocation.

以下是您如何获得以英里为单位的半径:

CLLocation * centerLeftLocation = [[CLLocation alloc] 
                                   initWithLatitude:centerCoord.latitude 
                                   longitude:topLeftCoord.longitude];
CLLocation * centerLocation = [[CLLocation alloc] 
                               initWithLatitude:centerCoord.latitude 
                               longitude:centerCoord.longitude];

CLLocationDistance distanceInMeters = [centerLeftLocation distanceFromLocation:centerLocation]; 

float distanceInMiles = distanceInMeters / 1609.344f; 

[centerLeftLocation release]; 
[centerLocation release]; 
于 2012-01-16T23:15:32.300 回答