CLLocation返回负速度

我正在开始一个使用coreLocation和mapkit框架的新应用程序。

我的问题是试图让当前的速度总是给我一个负值,我把我的iPhone带到一个3g信号好的地方并没关系,location.speed值总是-1。

这是重要的代码:

#define kRequiredAccuracy 1500.0 //meters #define kMaxAge 60.0 //seconds 

在init方法中:

 self.locationManager=[[CLLocationManager alloc] init]; self.locationManager.delegate=self; self.locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters; 

然后didUpdateToLocation:

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSTimeInterval ageInSeconds = [newLocation.timestamp timeIntervalSinceNow]; NSLog(@"Location: %@", [newLocation description]); if( newLocation.horizontalAccuracy > kRequiredAccuracy || fabs(ageInSeconds) > kMaxAge ) { NSLog(@"inacurate position"); [self.delegate inacuratePosition]; } else { [self.delegate locationUpdate:newLocation andOldLocation:oldLocation]; location=newLocation.coordinate; } if(tracking) { [self updatePosition]; } if(firstTime) { [self placeStartMark]; firstTime=FALSE; } } 

最后在我正在实现协议的视图控制器中:

 - (void)locationUpdate:(CLLocation *)newLocation andOldLocation:(CLLocation*)oldLocation{ double speed = [newLocation speed] *3.6; double altitude= [newLocation altitude]; [self checkMaxSpeedAndAltitude:speed :altitude]; if(speed< 0) speed=0; locationLabel.text=[NSString stringWithFormat:@"speed: %f km/h altitude: %fm", speed,altitude]; } 

我变得疯狂,所以如果有人知道任何解决方案,它肯定会有所帮助。 谢谢

通常,如果使用的位置检测机制不支持它,则会得到负的高度和速度。 例如,当使用Wi-Fi或小区三角测量时。 你确定,你正在获得GPS更新,所以你在自由天空下测试吗? 即便如此,您仍然会收到WiFi和手机信号塔位置更新,因此您需要将其过滤掉。

Wi-Fi位置更新通常为65米水平精度。