I am working on an application that uses the iPhone's magnetometer and accelerometer together. 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). 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.
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. Once calibrated, hold the iPhone straight up and down, in portrait mode, with the home bottom below the screen. 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.
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. If anyone has found a solution to this situation, it would be much appreciated!
Cheers.