从iOS中的RotationMatrix获取标题

从iOS中的RotationMatrix获取标题,ios,compass-geolocation,rotational-matrices,heading,cmmotionmanager,Ios,Compass Geolocation,Rotational Matrices,Heading,Cmmotionmanager,我从我的CMMotionManager收到旋转矩阵,并希望从中计算手机的航向,例如,北纬38度,避开CLLocationManager,以便制作更精确的罗盘: [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion

我从我的CMMotionManager收到旋转矩阵,并希望从中计算手机的航向,例如,北纬38度,避开CLLocationManager,以便制作更精确的罗盘:

 [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue mainQueue]  withHandler:^(CMDeviceMotion *deviceMotion, NSError *error) {

 CMRotationMatrix rm = deviceMotion.attitude.rotationMatrix;

 // Get the heading.
 motionHeading = M_PI + atan2(rm.m22, rm.m12);
 motionHeading = motionHeading*180/M_PI;
然而,这只有在手机平放在桌子上时才起作用。我应该使用什么作为公式来考虑手机在我手上的所有位置,处于横向模式,以及设备在地平线上方或下方的位置?谢谢。

我最终使用了这个公式,它在运动稳定性方面非常有效