【发布时间】:2011-06-07 11:04:39
【问题描述】:
我正在 iPhone 中开发一个速度计应用程序。我使用 CLLocationManager(基于 GPS)来测量车辆的速度。但我没有得到准确的速度。我已经尝试了各种 stackoverflow 讨论中给出的所有过滤方法。但我没有得到任何改善。有时,速度会达到更大的值(>400kmph)。
我不知道出了什么问题。请建议我任何代码以获得准确的速度。
提前致谢,
我已经关注了下面提到的堆栈溢出讨论
Measuring velocity via iPhone SDK
Optimizing CLLocationManager/CoreLocation to retrieve data points faster on the iPhone
Why is my CLLocation speed so inaccurate?
我目前已经实现了以下代码:
//locationManager declaration in ViewDidLoad
locManager=[[CLLocationManager alloc]init];
locManager.delegate =self;
[locManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSTimeInterval locationAge = abs([newLocation.timestamp timeIntervalSinceNow]);
if (locationAge > 5.0) return;
if (newLocation.speed < 0 || newLocation.horizontalAccuracy < 0) return;
if ((newLocation.horizontalAccuracy < (oldLocation.horizontalAccuracy - 10.0)) || (newLocation.horizontalAccuracy < 50.0)|| (newLocation.horizontalAccuracy <= 150.0))
{
if(oldLocation != nil)
{
CLLocationDistance distanceChange = [newLocation distanceFromLocation:oldLocation];
NSTimeInterval sinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
double calculatedSpeed;
calculatedSpeed = (distanceChange / sinceLastUpdate)*3.6; // to convert the speed into kmph.
}
}
}
【问题讨论】:
-
请提供引用的 StackOverflow 讨论的链接,因此没有人会浪费您的时间来解决您已经放弃的不可接受的解决方案。另外,请发布您现在使用的代码。
-
嗨杰里米,现在我已经添加了我使用的代码。请查看它。