Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager trueHeading is -1

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.

like image 678
Irfan DANISH Avatar asked Apr 07 '26 16:04

Irfan DANISH


1 Answers

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

enter image description here

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.

enter image description here

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.

like image 88
gpdawson Avatar answered Apr 11 '26 00:04

gpdawson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!