【发布时间】:2016-04-04 13:54:23
【问题描述】:
当用户开始跟踪对象时,我想使用 swift 2.2 查找移动对象的行程时间。我写了 locationManager 函数来跟踪移动对象的位置和行进距离,但我需要找到行进时间?
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)
}
【问题讨论】:
-
最基本的:时间=距离/速度
-
这里真正的问题是什么?在
StartTrip中记下时间似乎很容易?
标签: ios swift cllocationmanager cllocation