0

我正在开发一个健身追踪应用程序,如 Runtastic、Nike+ 等。我将从头到尾绘制整个活动的地图。我不会在应用程序启动时开始更新位置更改,而是在用户开始锻炼时开始更新。但是当 locationManager 开始更新时,前 3 到 5 个 CLLocations 是非常不正确的。误差高达一公里。我正在使用以下代码来初始化位置管理器:

self.locationManager = [(PFAppDelegate *)[[UIApplication sharedApplication] delegate] locationManager];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.locationManager.distanceFilter = 5.0;
[self.locationManager startUpdatingLocation];

在 locationManagerDidUpdateToLocation 方法中:

 if( didFindGPS == NO )
 {
     if( [[lastLocation timestamp] timeIntervalSinceNow] < 10.0 )
     {
         if( [lastLocation horizontalAccuracy] < 20)
         {
            didFindGPS = YES;
         }
     }
 }
 else
 {
     //process data here
 }

这不会过滤掉那些第一个不正确的位置。我也尝试过忽略horizo​​ntalAccury 值小于20 的位置,但是应用程序不会处理任何位置。

可以做些什么来改进第一个位置或处理第一个不正确的位置?

4

1 回答 1

1

改变

if ([lastLocation horizontalAccuracy] < 20)...

if (([lastLocation horizontalAccuracy] > 0) && ([lastLocation horizontalAccuracy] < 20))...

根据文档

负值表示该位置的经纬度无效。

负值horizontalAccuracy是。

如果您想设置处理数据的条件(看起来像您这样做),您应该将代码重写为:

if (([lastLocation horizontalAccuracy] > 0) && ([lastLocation horizontalAccuracy] < 20))
{
    didFindGPS = YES;
    //process the data here... since here the location fits your limitations
    //and you don't loose the first location (as in original code)
}
else
{
    didFindGPS = NO;
}

请注意,此代码可能会给您一些丢失 GPS 的错误警报,因此您可能希望省略 else 块。

于 2013-08-16T08:06:04.393 回答