ios - 如何将 CLLocationManager.magneticHeading 转换为弧度?

标签 ios swift xcode math cllocationmanager

我正在尝试将我看到的从 0 到 360 的磁航向数转换为弧度,以便我可以使用 CGPoint。但是,此代码会引发错误。

//Code to move on the X plane
let heading = self!.locManager.heading

let MagHeading = (heading?.magneticHeading)! * M_PI/180 //error

如何将从标题中获取的 CLLocation 值转换为 float ,以便将其转换为弧度? 错误是标题为零。然而,如果不进行转换,它仍然会产生值(value)

最佳答案

实际问题和你的问题完全不同。你需要在那里处理可选变量......但是你提到了 double / float 到弧度之间的转换

试试这个……至少你的错误会消失。

if let heading = self.locManager.heading {

    let MagHeading = (heading.magneticHeading) * M_PI/180
    print("MagHeading - \(MagHeading)")

}  else {

   print("heading is nil")

}

关于ios - 如何将 CLLocationManager.magneticHeading 转换为弧度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43005086/

相关文章:

iphone - Storyboard标识符的代码完成

ios - 缩放弹跳 + 导航栏后退按钮点击 = 应用程序崩溃

UTC 到本地时间的 IOS 转换不准确

ios - 使用带云代码的 Stripe + Parse 存储信用卡

arrays - 如何从字典数组的元素中获取 Int。代码

swift - 在 Swift 中存储指向变量的指针

ios - 安装不同版本的 iPhone 模拟器

ios - 将新 View 添加到层​​次结构时出现自动布局问题

ios - 在 App purchase 沙盒中——购买了项目但在下载托管内容时出错

ios - MPNowPlayingInfoCenter 不显示详细信息