iPhone位置角度

时间:2019-07-17 12:10:52

标签: ios swift iphone position

如何计算0到360度之间的iPhone位置角度。考虑将肖像设为0度?使用陀螺仪和加速度计感到很累,但无法获得角度。

1 个答案:

答案 0 :(得分:0)

如果motionManager.isDeviceMotionAvailable {

motionManager.startDeviceMotionUpdates(to: OperationQueue.main) { (motion, error) in

    let radians = atan2((motion?.gravity.x)!, (motion?.gravity.y)!) - .pi

    let degrees = radians * 180.0  / .pi

    print(-degrees)

}

}