SMP*_*SMP 8 iphone augmented-reality core-motion compass-geolocation
我正在使用CoreMotion获取ccompass标题,我注意到罗盘标题存在一些问题.
首先我初学CoreMotion.我有一个CMMotionManager对象,locationManager,它是CMMotionManager的一个实例.
// initialize CoreMotion
motionManager = [CMMotionManager new];
[motionManager setDeviceMotionUpdateInterval:1.0/30.0];
[motionManager setShowsDeviceMovementDisplay:YES];
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
Run Code Online (Sandbox Code Playgroud)
位置数据每1/30.0秒更新一次.
出于调试目的,我有一个UILabel,它显示每个更新间隔更新的当前罗盘标题.应用程序启动时,我总是要做神奇的8来校准指南针.
校准指南针后,北极和南极的航向几乎是2-5秒.
几秒钟后,指南针变得狂野,角度四处跳跃.大多数情况下,它从两个方向的起始位置漂浮在10-20度左右.应该有一个奇怪的结果.经过30-60秒后,南北两次互换或向东和向西交换.
在WWDC 2011上,一个会议讨论了他们如何计算每个传感器与另一个传感器以补偿这些问题.在CoreMotion的配置中是否有任何错过我有这个精确标题结果的大问题?
我现在用3个设备(2个iPhone 4s和iPhone 4)在建筑物内外测试指南针.我在田野,小城市和大城市.它一直在发生.来自Apple的示例指南针应用程序几乎准确,在我的测试中准确率为90%.不幸的是,它不是Apple开源的.
谢谢你的阅读.
通过CoreLocation使用 CoreMotion将为您提供所需的信息。
默认情况下,手机将执行数字 8 校准,要禁用此功能,请locationManagerShouldDisplayHeadingCalibration:按如下方式覆盖:
- (BOOL)locationManagerShouldDisplayHeadingCalibration: (CLLocationManager *)manager {
return NO;
}
Run Code Online (Sandbox Code Playgroud)
从您问题中的代码中不清楚您是否正在调用startUpdateHeading. 如果没有,请这样做:
if( [CLLocationManager locationServicesEnabled] && [CLLocationManager headingAvailable]) {
[myLocationManager startUpdatingLocation];
[myLocationManager startUpdatingHeading];
}
Run Code Online (Sandbox Code Playgroud)
如果您不打开标题过滤器,您可能会得到疯狂的结果,我建议您这样做。之后,您只需在didUpdateHeading调用时即可在位置管理器委托中获取标题更改。
另请注意,如果手机处于横向模式,您需要将航向调整适当的度数(+/- 90),因为航向始终位于纵向参考系中。