我使用这个代码来定义设备的位置。侧滚和俯仰值看起来很好(当设备放在桌面上时,它们是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];
}发布于 2016-03-10 23:30:18
当偏航为0时,手机必须指向北,不是吗?
你说的“电话”是什么意思?问题是,手机的哪一部分。让我们来读一下文档:
CMAttitudeReferenceFrameXTrueNorthZVertical
描述Z轴垂直且X轴指向正北的参考系。
X轴位于设备的右侧。因此,当设备的右侧为北时,您应该预期偏航为0。
https://stackoverflow.com/questions/35919772
复制相似问题