iPhone:在横向右侧和横向左侧之间使用罗盘标题值进行偏移

Tíb*_*íbó 2 augmented-reality cllocationmanager ios compass-geolocation

要清楚我的问题是没有在横向或左边读取横向的标题值.它运行正常我正在使用位置管理器并减去90°来读取横向右侧的标题值和左侧的270°,默认情况下设备始终被视为纵向模式,这就是我们必须进行此调整的原因.

我最近开发了一个基于位置的增强现实应用程序,我正在经历的是,左右横向之间的标题值始终存在偏移.我在"现场"测试,偏移约为12°.

我希望这个应用程序尽可能准确,我的意思是因为我们依赖于传感器数据,这是第一个版本,小于10°是可以接受的(在最坏的情况下甚至是15°).但是如果我们将现有误差添加到12°的偏移量,那就非常烦人了.

有没有人对此有解释?即使我现在无法修复它,我也希望有一个.所以现在我试图通过向左侧的景观添加12°来"修复"这个,或者我可能宁愿减去12°到景观,我不知道!

有关这个问题的经验吗?

Ste*_*ten 8

我的经验是指南针不是很好,尤其是在景观视图中.我不会在一个视图中减去12°,因为差异可能是另一个设备上的其他东西.我建议您在继续之前测试一两台其他iPhone.

另外,您是否设置了LocationManager的视图?

CLLocationManager *compassManager;
compassManager.headingOrientation =CLDeviceOrientationLandscapeLeft;
Run Code Online (Sandbox Code Playgroud)

  • compassManager.headingOrientation +1 =CLDeviceOrientationLandscapeLeft; - 帮助我 (2认同)

小智 6

我也刚刚遇到这个问题,LandscapeLeft、landscapeRight 和 Portrait 之间是有区别的。感谢 Sten 的回复和下面的 Swift 代码解决了这个问题。

override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
    var text=""
    switch UIDevice.currentDevice().orientation{
    case .Portrait:
        text="Portrait"
        locationManager.headingOrientation = CLDeviceOrientation.Portrait
    case .PortraitUpsideDown:
        text="PortraitUpsideDown"
        locationManager.headingOrientation = CLDeviceOrientation.Portrait
    case .LandscapeLeft:
        text="LandscapeLeft"
        locationManager.headingOrientation = CLDeviceOrientation.LandscapeLeft
    case .LandscapeRight:
        text="LandscapeRight"
        locationManager.headingOrientation = CLDeviceOrientation.LandscapeRight
    default:
        text="Another"
    }
    NSLog("You have moved: \(text)")
Run Code Online (Sandbox Code Playgroud)
}
Run Code Online (Sandbox Code Playgroud)