简体   繁体   English

CLLocationManager标题与倾斜设备

[英]CLLocationManager heading with tilted device

I am working on an application that uses the iPhone's magnetometer and accelerometer together. 我正在开发一个使用iPhone的磁力计和加速度计的应用程序。 I problem I have noted is that when the device is tilted back, it hits a critical point at which the heading values are reversed (iOS seems to think that the device has been rotated around). 我的问题我已经注意到,当设备向后倾斜时,它会遇到标题值反转的临界点(iOS似乎认为设备已经旋转)。 At first I thought it would be simple as checking when the device's orientation changed ( [UIDevice currentDevice].orientation ), but *the heading values reverse significantly before (at least 15 degrees of tilt) the device orientation change notification is sent. 起初我认为检查设备的方向何时改变( [UIDevice currentDevice].orientation )会很简单,但*标题值在发送设备方向改变通知之前(至少倾斜15度)显着反转。

I apologize if this description is confusing, but you can easily see my issue with the following experiment: 如果此描述令人困惑,我很抱歉,但您可以通过以下实验轻松查看我的问题:

Open the compass app on an iPhone and calibrate the compass. 在iPhone上打开指南针应用程序并校准指南针。 Once calibrated, hold the iPhone straight up and down, in portrait mode, with the home bottom below the screen. 校准完毕后,以纵向模式将iPhone垂直向上和向下,屏幕下方的主页底部。 Now slowly tilt the phone backward (so the camera is facing more directly upward). 现在慢慢向后倾斜手机(因此相机更直接朝上)。 You will hit a point where the compass suddenly reverses its direction. 你会发现指南针突然转向它的方向。 Unfortunately, this point is not correlated with the point where the OS recognizes a device orientation change. 不幸的是,这一点与OS识别设备方向变化的点无关。

My problem is that I need to continue to register the heading in the original direction, as I haven't actually turned the device around and it is clearly still pointing forwards (in the original direction). 我的问题是我需要继续在原始方向上注册标题,因为我实际上没有转动设备,它显然仍指向前方(在原始方向)。 I have tested for the angle of the device at this critical point and had some success correcting for it this way, but I get very jittery results around the critical angle due to the noise from the accelerometer. 我已经在这个临界点测试了设备的角度,并且通过这种方式取得了一些成功的修正,但由于加速度计产生的噪音,我在临界角附近得到了非常抖动的结果。 I have also experimented with the location manager's headingOrientation property with no success. 我还尝试了位置管理器的headingOrientation属性但没有成功。 If anyone has found a solution to this situation, it would be much appreciated! 如果有人找到了这种情况的解决方案,我将不胜感激!

Cheers. 干杯。

A bit more background on why you need this would be helpful to provide better answers. 关于你为什么需要这个的更多背景将有助于提供更好的答案。 When doing the move you describe, the top of the device is actually pointing into the opposite direction. 在进行您描述的移动时,设备的顶部实际上指向相反的方向。
To compensate for this, you will need to add a filter and determine the new state of the device angles and heading based on the previous state of the device angles and heading. 为了弥补这一点,您需要添加一个过滤器,并根据设备角度和航向的先前状态确定设备角度和航向的新状态。 Knowing that the device angles are approaching the critical phase and knowing that the heading suddenly reversed by 180° should enable you to distinguish this case. 知道设备角度接近临界阶段并且知道航向突然反转180°应该能够区分这种情况。 You could add gyro information to the filter to use device rotation rates and determine that the device is being moved over the critical angle. 您可以将陀螺仪信息添加到滤波器以使用设备旋转速率并确定设备正在临界角移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM