Reputation: 147
Basically I want to know the direction iPhone is pointing with high precision, I tried CLLocationManager: the problem is the CLHeading.magneticHeading returns a double for example 36.44323 but then when I start turning the device, CLLocationManager only updates the direction when it reaches 1 degree, so the numbers read like this : 36.44323, 37.44323, 38.44323 and so on. Is it possible to have more accuracy?
Upvotes: 1
Views: 2307
Reputation: 51
Set CLLocationManager
headingFilter
to kCLHeadingFilterNone
or anything less than the default 1 degree.
Upvotes: 5
Reputation: 606
You should use the Gyro if you need more accuracy. The device motion data from CoreMotion should help you with that. Compass really isn't accurate enough.
Upvotes: 0
Reputation: 23
If you don't care about the accuracy but are interested in the small changes in direction then you may want to look at CMMotionManager
. It was a property (deviceMotion
) which will allow you to get the attitude
of the device, in particularly the yaw
. By recording the difference (say x
) between the yaw & magnetic heading on each heading update you can get the approximate heading in between updates as yaw + x
. You will receive timelier updates from CMMotionManager
because you can set the deviceMotionUpdateInterval
yourself.
If I remember correctly the yaw
value is returned in radians between -pi and pi so you will need to convert back to degrees when calculating x
as CLLocationManager
will return the magnetic heading is degrees (0 to 360).
You will probably want to make adjustments for device orientation as well. The compass returns heading data from the top of the device so if you are in landscapeLeft you will need to subtract 90° from the heading value, landscapeRight you will need to add 90° to the heading value and portraitUpsideDown will require an adjustment of 180°.
Upvotes: 2
Reputation: 38475
Not that I know of, no.
And don't confuse accuracy with correctness; just because it says 36.44323 doesn't mean it's accurate to 5 decimal places, the error bounds on that value might be ±1 degree :(
I don't think that the compass on an iPhone has high enough precision to say with any real confidence which direction you are pointing to the accuracy you want. Sorry!
Upvotes: 1