Search code examples
iphoneiosobjective-cdictionary

Compass calibration objective-c


I try use compass in my ios app. And I have one problem with it. If i implement locationManagerShouldDisplayHeadingCalibration method and return YES in it, then calibration display is showing always. But I should make it like apple maps. I.e. calibration display should be showed sometimes. When compass should be calibration.


Solution

  • OK I could not leave a comment so I thought I should leave a reply as Claude Houle's reply was useful to me.

    I am using this improved version of Claude Houle's response.

    - (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager{
          if(!manager.heading) return YES; // Got nothing, We can assume we got to calibrate.
          else if(manager.heading.headingAccuracy < 0 ) return YES; // 0 means invalid heading, need to calibrate
          else if(manager.heading.headingAccuracy > 5 ) return YES; // 5 degrees is a small value correct for my needs, too.
          else return NO; // All is good. Compass is precise enough.
    }
    

    Also wanted to say what Claude Houle says almost implements the API docs here which states:

    If you return NO from this method or do not provide an implementation for it in your delegate, Core Location does not display the heading calibration alert. Even if the alert is not displayed, calibration can still occur naturally when any interfering magnetic fields move away from the device. However, if the device is unable to calibrate itself for any reason, the value in the headingAccuracy property of any subsequent events will reflect the uncalibrated readings.