我正在使用 iPhone SDK,我想在我的应用程序中显示当前速度。有很多应用程序可以做到这一点非常精确,特别是对于跑步或骑自行车等低速行驶。我见过的最好的是RunKeeper。
但是,在我的应用程序中,速度绝对不准确。在低速时它始终为空,只有在高速时它才会显示一些值,但它们很少更新并且不是真正有用的。
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
if (newLocation.timestamp > oldLocation.timestamp &&
newLocation.verticalAccuracy > 0.0f && // GPS is active
newLocation.horizontalAccuracy < 500.0f && // GPS is active
//newLocation.horizontalAccuracy < kCLLocationAccuracyHundredMeters && // good quality GPS signal
//newLocation.speed > 1.0f && // enough movment for accurate speed and course measurement
oldLocation != nil) // oldLocation is nil on the first reading
{
double speed = (newLocation.speed * 3.6);
[self updateDisplayWithSpeed:speed];
//double direction = newLocation.course;
}
}
有没有人有工作代码?或者你能告诉我我的有什么问题吗?