ios - 将学位转换为iOS学位系统

标签 ios swift math geometry

所以我尝试使用

从两个位置坐标中找到方位

https://www.sunearthtools.com/tools/distance.php .

输入

坐标 A : 21.642534, 69.607003, 坐标 B : 21.642083, 69.614587

输出为 93.66 度

enter image description here

现在我想在圈子上展示这个所以我使用下面的代码

    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我们有不同的学位系统

enter image description here

enter image description here

如何将学位系统转换为 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/

相关文章:

ios - iOS BLE 中心如何在通知模式下从外设接收超过 182 个字节?

c++ - 使用 L1 范数的多项式拟合

iphone - fmodf 获取模数的问题

ios - 当两个 View 在同一个地方时,如何控制显示和隐藏?

ios - iOS 中密码字段的字母数字验证

ios - 使用 AutoLayout 以编程方式创建 UICollectionView

swift - 线程 1 : signal SIGABRT in Reachability framework in custom framework Swift

swift - UITableViewAutomaticDimension-10.0

c++ - 随机函数可以返回的范围是多少?

ios - 如何从 Swift 单元测试访问测试目标中存在的 Objective-C 代码?