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

标签 ios mapkit

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

我正在使用以米为单位的半径:

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

我在这里缺少什么吗?让圆圈关闭但稍微偏离一点是非常令人沮丧的。在较小的距离上,我可以放大最大数量并让大头针准确地接触我圈子的外线。

最佳答案

问题可能是因为纽约和洛杉矶位于不同的纬度,并且在 map 上以赤道为中心的半径为 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.

关于ios - 使用由两个远点定义的半径绘制的 MKCircle 渲染不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18501185/

相关文章:

ios - 如何在 Swift 中使用 'FMDB/SQLCipher' 加密和解密?

ios - 检测用户在 map 上点击的路线

ios - 点击时自定义注释的边框会 swift 超出(而不是进入)

ios - 如何使用 addObserver 闭包方法在 Swift 5 中删除Observer

ios - 如何在 Interface Builder 中添加 MKUserTrackingBarButtonItem

ios - 如何在不使用 UINavigationController 的情况下以编程方式进入 rootViewController

iOS RTMP 流媒体库 - LFLiveKit vs VideoCore lib vs alternative

ios - 如何使用 Swift 显示自定义注释,即使它位于用户当前位置

ios - 我可以将自定义 Google map 导入 iOS MapKit 吗?

ios - 如何清除mkmapview的缓存