I want to find travel time of moving object using swift 2.2 when user start tracking the object. I wrote locationManager function to track the moving object location and travel distance but I need to find travel time?
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)
}