1

I am trying to show compass on my screen

if ([CLLocationManager headingAvailable]) {
    CLController.locMgr.headingFilter = 0.1;
    [CLController.locMgr startUpdatingHeading];
}

it goes into method, and goes into method

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
if (newHeading.headingAccuracy < 0){
    NSLog(@"heading accuracy < 0");
    return;
}
// Use the true heading if it is valid.
CLLocationDirection  direction = ((newHeading.trueHeading > 0) ?
                                   newHeading.trueHeading : newHeading.magneticHeading);

[self.delegate headingUpdate:direction];

}

Earlier it was working fine, but dont know what happened now,

It's showing "heading accuracy < 0"..

Rohit Singhal
  • 381
  • 1
  • 4
  • 22
  • I read Apple Doc...they have written -"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.".. – Rohit Singhal Oct 11 '11 at 13:26
  • Take a look at this [answer](http://stackoverflow.com/questions/1081219/optimizing-cllocationmanager-corelocation-to-retrieve-data-points-faster-on-the-i). I might help you – Daniel Oct 11 '11 at 13:46
  • I am really sorry but I could not get my answer from this post.. I am confused as earlier this app was working perfectly, but now its giving error.. One more strange thing, i installed 1 more app on compass, that too not working properly... I guess there is some issues with device settings... Please help- me out..... – Rohit Singhal Oct 12 '11 at 05:15
  • Make sure there is only location manager running. Maybe another app is running something in background mode that is interfering? ..just a guess – Daniel Oct 12 '11 at 08:40

1 Answers1

3

A negative headingAccuracy value simply means that the compass cannot get a good reading at the moment. Perhaps the phone is near some strong magnetic field or you need to wave it in a figure 8 to calibrate the compass. It doesn't mean your code is incorrect.

Just ignore the heading updates where the headingAccuracy < 0, and only use the other values you get. This is normal behaviour.

progrmr
  • 75,956
  • 16
  • 112
  • 147