1

My didUpdateHeading code is below:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    if (newHeading.headingAccuracy < 0)
    {
        _realHeading = -9999;

        NSLog(@"heading accuracy < 0");

        return;
    }


    // Use the true heading if it is valid.
    [self.locationManager dismissHeadingCalibrationDisplay];

    _newHeading = Retain(newHeading);


    if (self.useMagneticHeading == YES)
        _realHeading = _newHeading.magneticHeading;
    else
        _realHeading = _newHeading.trueHeading;


    // Adjust for device rotation.
    UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;

    switch (orientation)
    {
        case UIDeviceOrientationPortraitUpsideDown:
            _realHeading = _realHeading + 180.0f;
            break;
        case UIDeviceOrientationLandscapeLeft:
            _realHeading = _realHeading + 90.0f;
            break;
        case UIDeviceOrientationLandscapeRight:
            _realHeading = _realHeading + 270.0f;
            break;
        default:
            break;
    }
    while (_realHeading > 360.0f)
        _realHeading = _realHeading - 360;



}

It works.

But it's jumpy. The sensor swings and fluctuates quite a bit.

Has anyone managed to somehow improve the stabilization and accuracy of the built-in iPhone compass?

Perhaps with the use of other sensors (accel?, gyro?). Or maybe some software algorithm?

Sebastian Dwornik
  • 2,526
  • 2
  • 34
  • 57

0 Answers0