首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >中心与边界的MKCoordinateRegion距离

中心与边界的MKCoordinateRegion距离
EN

Stack Overflow用户
提问于 2011-11-26 01:24:37
回答 2查看 6.3K关注 0票数 4

(根据意见修订的问题:)

好的,我试着在其他的way...How中问,我能得到这个圆圈覆盖的边框坐标吗:

(原问题:)

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

我想得到这个地区的边界点,所以我有这样的代码:

代码语言:javascript
复制
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 (伦敦)进入时,并进行坐标:

代码语言:javascript
复制
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英里。

谢谢你的答复

EN

回答 2

Stack Overflow用户

发布于 2011-11-26 04:30:33

(根据评论意见修订的答复:)

如果您的意思是希望该圆圈覆盖的边界矩形的坐标,请使用覆盖的boundingMapRect属性:

代码语言:javascript
复制
//"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英里,那么至少要调整其中一个跨度。即使您要求根据视图的比例设置一个跨度,如果地图视图不能在该缩放级别上显示瓷砖(或者如果您没有考虑到地球的曲率),仍然可以对其进行调整。

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

因此,不能将屏幕截图中的测试与span增量进行比较。在屏幕截图中,您正在计算从中心坐标到最小纬度和经度(左下角)的距离,但是跨度三角洲从右到左、从下到上一直走。(正因为如此,你会认为从中心到拐角处的距离应该小于三角洲,而不是更远。)它较短,但由于上述原因,三角洲也增加到10多个)。

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

代码语言:javascript
复制
CLLocationCoordinate2D bottomLeftCoord = 
    [myMapView convertPoint:CGPointMake(0, myMapView.frame.size.height) 
               toCoordinateFromView:myMapView];

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

Stack Overflow用户

发布于 2012-01-16 23:15:32

在web表单的屏幕截图中,您将得到一个不同的距离,因为您正在测量的线(中心到MinLAT / MinLONG)是对角线,并且超出了圆圈半径。

如果您遵循@AnnaKarenina的回答,那么您就可以通过将每个CLLocationCoordinate2D转换为一个CLLocation来获得以米为单位的距离。

以下是以英里为单位计算半径的方法:

代码语言:javascript
复制
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]; 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8275605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档