CMAttitudeReferenceFrameXTrueNorthZVertical 不指向北

am1*_*1kk 2 objective-c core-motion

我正在使用此代码来定义设备位置。横滚和俯仰值看起来不错(当设备放在桌子上时,它们为 0),但当偏航为 0 时,罗盘指向西。怎么了?

        [self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue]
                                                   withHandler: ^(CMDeviceMotion *motion, NSError *error){
                                                       [self performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES];
                                                   }];
    }
}

- (void)handleDeviceMotion:(CMDeviceMotion*)motion {
   CMAttitude *attitude = motion.attitude;
   double yaw = attitude.yaw * 180 / M_PI;
   double pitch = attitude.pitch * 180 / M_PI;
   double roll = attitude.roll * 180 / M_PI;
   self.xLabel.text = [NSString stringWithFormat:@"%7.4f", yaw];
   self.yLabel.text = [NSString stringWithFormat:@"%7.4f", pitch];
   self.zLabel.text = [NSString stringWithFormat:@"%7.4f", roll];
   [self sendDeviceAttitudeLogWithYaw:yaw pitch:pitch roll:roll];
}
Run Code Online (Sandbox Code Playgroud)

mat*_*att 5

当偏航角为0时,手机必须指向北,不是吗?

“电话”是什么意思?问题是,手机的哪个部分。让我们阅读文档:

CMAttitudeReferenceFrameXTrueNorthZVertical

描述一个参考系,其中 Z 轴垂直,X 轴指向正北。

X 轴从设备的右侧延伸出来。因此,当设备右侧朝北时,您应该预期偏航为 0。