ユーザーがオブジェクトの追跡を開始するときに、swift 2.2を使用して移動するオブジェクトの移動時間を探したいと思います。移動オブジェクトの位置と移動距離を追跡するlocationManager関数を書きましたが、移動時間を見つける必要がありますか?移動時間の計算CLLocation Swift
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
userLocations.append(locations[0] as CLLocation)
if startLocation == nil {
startLocation = locations.first! as CLLocation
} else {
let distance = startLocation.distanceFromLocation(locations.last! as CLLocation)/1000
let lastDistance = lastLocation.distanceFromLocation(locations.last! as CLLocation)/1000;
vartraveledDistance += lastDistance
print("\(startLocation)")
print("\(locations.last!)")
print("FULL DISTANCE: \(traveledDistance)")
print("STRAIGHT DISTANCE: \(distance)")
}
lastLocation = locations.last! as CLLocation
}
@IBAction func StartTrip(sender: AnyObject) {
print("Start Trip")
locationManager.startUpdatingLocation()
}
@IBAction func StopTrip(sender: AnyObject) {
print("End Trip")
locationManager.stopUpdatingLocation()
traveledDistance.text = String(format:"%f km", self.vartraveledDistance)
}
最も基本的な:時間=距離/スピード – Darko
をここで本当の問題は何ですか? 'StartTrip'の時間をメモしておくのは簡単でしょうか? – zcui93