gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:47:56 26 4
gpt4 key购买 nike

我创建了一个绘制 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com