所以我尝试使用
从两个位置坐标中找到方位https://www.sunearthtools.com/tools/distance.php .
输入
坐标 A : 21.642534, 69.607003, 坐标 B : 21.642083, 69.614587
输出为 93.66 度
现在我想在圈子上展示这个所以我使用下面的代码
let view = UIView(frame: self.view.bounds)
self.view.addSubview(view)
let circle = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width - 20, height: view.frame.width - 20))
view.addSubview(circle)
circle.center = view.center
circle.layer.cornerRadius = circle.frame.height / 2
circle.backgroundColor = UIColor.gray.withAlphaComponent(0.7)
let dotView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 10))
dotView.layer.cornerRadius = dotView.frame.width / 2
dotView.backgroundColor = UIColor.purple.withAlphaComponent(0.89)
dotView.center = circle.center
circle.addSubview(dotView)
let location1 = CLLocation(latitude: 21.642534, longitude: 69.607003)
let location2 = CLLocation(latitude: 21.642083, longitude: 69.614587)
let angleStep = CGFloat(location1.bearingRadianTo(location: location2))
print(location1.bearingDegreesTo(location: location2))
let xPos = cos(angleStep) * (circle.frame.width / 2)
let yPos = sin(angleStep) * (circle.frame.width / 2)
dotView.center = CGPoint(x:circle.center.x + xPos - circle.frame.origin.x, y:circle.center.y + yPos - circle.frame.origin.y);
输出是紫色的点在底部,它应该在右侧就像第一张图片一样。
我已经验证我在 angleStep
中得到了正确的值
经过一些谷歌我发现对于iOS我们有不同的学位系统
如何将学位系统转换为 iOS 学位系统,以便在右侧显示紫色圆圈?
提前致谢
最佳答案
真实世界的航向使用 0 度表示北(上)。但正如您在上一张图中看到的那样,0 度是在 iOS 坐标系中的右侧,而不是顶部。您需要做的就是从 angleStep
中减去 π/2 弧度,将“真实”标题转换为“iOS”标题。
let angleStep = CGFloat(location1.bearingRadianTo(location: location2)) - CGFloat.pi / 2
关于ios - 将学位转换为iOS学位系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57567980/