如何计算0到360度之间的iPhone位置角度。考虑将肖像设为0度?使用陀螺仪和加速度计感到很累,但无法获得角度。
答案 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)
}
}