我正在玩iPhone SDK,我想在我的應用程序中顯示當前的速度。有這麼多的應用程序可以做到非常精確,特別是對於跑步或騎自行車等低速運動。我見過的最好的是RunKeeper。爲什麼我的CLLocation速度不準確?
但是,在我的應用程序中,速度是絕對不準確的。在低速時它總是無效的,只有在更高的速度下它纔會顯示一些數值,但它們很少被更新並且不是很有用。
- (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;
}
}
有沒有人有工作代碼?或者你能告訴我我的問題嗎?
你有一個代碼示例來處理第一個問題?或者,這只是檢查與前一個位置的時間戳? – 2014-03-20 08:40:25