Reputation: 8489
I am facing issue in using CLLocationManager
.
I am using startUpdatingLocation
method and its delegate method
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
I am gettings newHeading.trueHeading
.
The problem is some of the times newHeading.trueHeading
returns -1 and once device start returing -1 it remains the same, means it always returns -1.
Can anyone tell me the technical details of this problem and workaround to fix it.
While exploring Apple's document i found
"A negative value means that the reported heading is invalid, which can occur when the device is uncalibrated or there is strong interference from local magnetic fields."
But no information how to avoid or workaround.
Note: I am testing this app on real devices iPhone 4, iPhone 4S, iPad 2 and iPad 3.
Upvotes: 3
Views: 881
Reputation: 711
If you are finding that .magneticHeading has a valid heading (0 to 360) but .trueheading has invalid value (-1) then this usually means that the user has switched OFF the following setting:
Privacy / Location / System Services / Compass Calibration
Switching this back ON remedies the problem.
You can also check Apple's compass app Settings to see if it has the "Use True North" setting enabled or not. When the Compass Calibration setting is disabled, then this setting is also disabled.
Alas, Apple does not provide any means to test for this other than to observe that magnetic heading is available and true heading is not, and to then assume that this must be because the user has disabled the compass calibration setting.
Upvotes: 2
Reputation: 28727
But no information how to avoid or workaround.
In that case iOS
would like to display a calibration dialog, if you do not suppress this dialog. The heading becomes valid once the user calibrated the device by making a figure 8 motion.
If this cannot work because there are permanent strong magnetic fields, like inside a car, then there is simply no chance to get a magnetic heading.
In that case you may consider using location.course from location manger which gives the direction which the user moves, measured by GPS.
Upvotes: 1
Reputation: 20541
You can retrieve raw magnetic values along the X,Y and Z axes with CLHeading
properties. These value are measured in microteslas and normalized into range that Apple states is -128 to 128. Each axis value represents an offset from the magnetic field lines tracked by the device's built in magnetometer.
See this link for More Information.. books
i hope this will be helpful to you...
Upvotes: 0