因此,在我目前的project
我正在做一個計算駕駛摩托車時節省的排放量與一般汽車相比的方法。該功能包含兩部分,method
(計算)和tracker function
。主要問題是跟蹤器功能似乎根本沒有跟蹤。快速計算總距離iOS
我的主要問題是,如何在應用程序啓動時獲取跟蹤器功能總是跟蹤?
這是跟蹤功能
var startLocation:CLLocation!
var lastLocation: CLLocation!
var traveledDistance:Double = 0
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if startLocation == nil {
startLocation = locations.first
} else {
if let lastLocation = locations.last {
let distance = startLocation.distanceFromLocation(lastLocation)
let lastDistance = lastLocation.distanceFromLocation(lastLocation)
traveledDistance += lastDistance
print("\(startLocation)")
print("\(lastLocation)")
print("FULL DISTANCE: \(traveledDistance)")
print("STRAIGHT DISTANCE: \(distance)")
var travelDistance = setData("distance")
}
}
lastLocation = locations.last
}
這是方法
func calculateEmission(numbers: Int...) -> Double{
let recordedDistance = getData("distance")
let dis = recordedDistance
let emissionAve = 0.16
let calculatedEmission : Double = Double(dis) * Double(emissionAve)
print(calculatedEmission, "kg Co2")
return calculatedEmission
}
是什麼讓你相信這個方法應該被調用?你是否在某處創建了一個'CLLocationManager',你是否將它設置爲包含此方法的類的實例? – Jonah
這個問題還是很模糊的。請準確瞭解您要查找的信息。 – Sethmr
您是否得到提示授予位置服務訪問權限? – MwcsMac