1

我的 didUpdateHeading 代码如下:

- (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;



}

有用。

但它很跳跃。传感器摆动和波动很大。

有没有人设法以某种方式提高内置 iPhone 指南针的稳定性和准确性?

也许使用其他传感器(加速度?陀螺仪?)。或者也许是一些软件算法?

4

0 回答 0