使用核心位置框架计算 kilometer/hour 的速度
calculate the speed in kilometer/hour using core location framework
我正在计算距离和速度如下。
totalDistance=totalDistance+[newLocation distanceFromLocation:self
->tempOldLocation];
distanceLabel.text= [NSString stringWithFormat:@"%.2f km", (totalDistance
/1000)];
self->tempOldLocation=newLocation;
计算速度:
CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
NSTimeInterval sinceLastUpdate = [newLocation.timestamp
timeIntervalSinceDate:oldLocation.timestamp];
double calculatedSpeed = distanceChange / sinceLastUpdate;
我想在km/h中计算速度。请建议我在 km/h.
中计算速度的任何方法
您似乎在将米除以秒,等于米每秒。
米转KMS,秒转小时
double calculatedSpeed = (distanceChange / 1000) / (sinceLastUpdate / 60 / 60)
您将直接从 CLLocation
的 CLLocationSpeed
属性 获得速度,在委托方法 didUpdateLocation
中获得。
在 CLLocationManagerDelegate 中使用方法 didUpdateLocations:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let speed = locations.last?.speed else { return }
viewModel.speed.value = speed * 3600/1000
}
我正在计算距离和速度如下。
totalDistance=totalDistance+[newLocation distanceFromLocation:self
->tempOldLocation];
distanceLabel.text= [NSString stringWithFormat:@"%.2f km", (totalDistance
/1000)];
self->tempOldLocation=newLocation;
计算速度:
CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
NSTimeInterval sinceLastUpdate = [newLocation.timestamp
timeIntervalSinceDate:oldLocation.timestamp];
double calculatedSpeed = distanceChange / sinceLastUpdate;
我想在km/h中计算速度。请建议我在 km/h.
中计算速度的任何方法您似乎在将米除以秒,等于米每秒。 米转KMS,秒转小时
double calculatedSpeed = (distanceChange / 1000) / (sinceLastUpdate / 60 / 60)
您将直接从 CLLocation
的 CLLocationSpeed
属性 获得速度,在委托方法 didUpdateLocation
中获得。
在 CLLocationManagerDelegate 中使用方法 didUpdateLocations:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let speed = locations.last?.speed else { return }
viewModel.speed.value = speed * 3600/1000
}