基本上我的应用程序中的位置控制器工作。但是如果它运行了很长时间,它就会在没有识别的情况下得到错误的位置。我认为gps-buffer溢出或类似。
这是我的didUpdate-Event
的代码
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//nonvalid
if (signbit(newLocation.horizontalAccuracy))
return;
//0.0 is no valid location here
if ((abs(newLocation.coordinate.latitude) < 1.0e-05) || (abs(newLocation.coordinate.longitude) < 1.0e-05))
return;
if (newLocation.horizontalAccuracy > DBL_MAX)
return;
@synchronized(self)
{
currentCoordinate.latitude = newLocation.coordinate.latitude;
currentCoordinate.longitude = newLocation.coordinate.longitude;
}
//nonvalid
if (signbit(newLocation.horizontalAccuracy))
return;
//0.0 is no valid location here
if ((abs(newLocation.coordinate.latitude) < 1.0e-05) || (abs(newLocation.coordinate.longitude) < 1.0e-05))
return;
if (newLocation.horizontalAccuracy > DBL_MAX)
return;
@synchronized(self)
{
currentCoordinate.latitude = newLocation.coordinate.latitude;
currentCoordinate.longitude = newLocation.coordinate.longitude;
}
是否可以刷新位置缓冲区? 或用三角测量值控制位置?
答案 0 :(得分:1)
您还应该测试位置数据的年龄。这是最接近刷新缓存的东西(这是不可能的)。检查timestamp
属性并拒绝更新,如果它太旧了。
// check that the location data isn't older than 60 seconds
if ([newLocation.timestamp timeIntervalSinceReferenceDate] < [NSDate timeIntervalSinceReferenceDate] - 60) {
return;
}