2010-06-25 162 views
0

基本上,我的应用程序中的位置控制器正常工作。但是,如果它运行了很长时间,它就会在不承认它的情况下出错。我认为gps缓冲区溢出或那种。GPS获取错误位置

这里是我的didUpdate-事件

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

}

代码有可能刷新位置缓存? 或用三角测量值来控制位置?

+0

只要添加标签“iphone”,就不必在标题中包含“iPhone”。 :) – Emil 2010-06-25 12:43:24

+0

你在说多久?这似乎不太可能,这不会完全由苹果测试;) – deanWombourne 2010-06-25 13:33:04

回答

1

您还应该测试您的位置数据的年龄。这是刷新缓存最接近的事情(这是不可能的)。检查timestamp属性并拒绝更新,如果它太旧。

// check that the location data isn't older than 60 seconds 
if ([newLocation.timestamp timeIntervalSinceReferenceDate] < [NSDate timeIntervalSinceReferenceDate] - 60) { 
    return; 
}