1

我正在尝试从 GPS 检索数据,但它不是那么准确。这是一个屏幕截图:

全球定位系统

它与模拟器上的 GPS 仿真配合得很好。我想知道如何改进这一点。

这是我尝试过的代码:

    UserLocation = [[CLLocationManager alloc] init];
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
    [UserLocation setPausesLocationUpdatesAutomatically:NO];
    [UserLocation setActivityType:CLActivityTypeFitness];
#endif
   UserLocation.delegate = self;
    [UserLocation setDistanceFilter:kCLDistanceFilterNone];
    [UserLocation setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [UserLocation startUpdatingLocation];

然后我每秒检索一次数据并检查它是否与前一个不同。

4

1 回答 1

2

Ric Perrott is right about the GPS data never being 100% accurate all the time. I suggest you set your accuracy to kCLLocationAccuracyBest which according to Apple is the right setting for what you are trying to do.

To try and filter out some of the 'jumping' you are getting, I suggest taking an average reading. For example, take X number of GPS readings (5 or 10 or...) and then average out. This will eliminate the occasional incorrect reading your device might get.

I wrote a fitness walking app a while back and had similar issues. Averaging did not completely resolve the issue but it did smooth it out a lot.

于 2013-07-23T16:24:20.343 回答