用两个远点定义的半径绘制的MKCircle渲染不正确

时间:2013-08-29 02:02:44

标签: ios mapkit

我创建了一个地图显示,绘制了2个点,并且想要创建一个以1个点为中心的MKCircle,并使圆的边缘穿过另一个点。这应该像创建一个半径等于2个点之间的距离并围绕其中一个点居中的圆一样简单。这似乎在较小的距离上工作得很好,但是在一定距离之后,圆的半径不再与第二点匹配。 (在我的测试中,我在洛杉矶和纽约绘制了一个点。)

我使用以下方式获取我的半径:

CLLocationDistance dist = [loc1 distanceFromLocation:loc2];
NSLog(@"dist: %f", dist);

我正在使用:

绘制圆圈
MKCircle *circle = [MKCircle circleWithCenterCoordinate:coord1 radius:dist];
[circle setTitle:@"background"];
[mMapView addOverlay: circle];
MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:coord2 radius:dist];
[circleLine setTitle:@"line"];
[mMapView addOverlay: circleLine];

我在这里缺少什么吗?将圆圈关闭但稍微关闭是非常令人沮丧的。在较小的距离,我可以放大最大量,并使针与我的圆的外线完全接触。

1 个答案:

答案 0 :(得分:0)

麻烦可能是因为NY和LA处于不同的纬度,并且在赤道上居中的半径为X米的圆在地图上比在半径附近具有相同半径的另一个圆更小。如果您需要图片http://www.gpsvisualizer.com/examples/range_rings.html

,请查看此页面上的第二张地图

那么如何获得正确的半径?如果您知道将要显示的缩放级别,您可以尝试这种(完全未经测试的)算法:

1. Convert the two geo-points to map points
2. Workout the distance in map points
3. use that distance to create a new map point at the same y coordinate offset from the center point (full left or full right won't matter)
4. convert this point to a geo-point
5. workout the distance between it at the center geo-point
6. use that as your radius.