当前位置和更新位置之间的距离

时间:2018-11-26 10:54:43

标签: swift location cllocationmanager

我想得到两个位置之间的距离。

第一个位置是我当前的位置,另一个位置是用户更新的位置。

因此,如何跟踪用户位置以及如何测量当前位置和用户更新的位置之间的距离

我尝试了这段代码,但测量结果不正确。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let loc = locations.last else {return}

    guard let startLocation = startLocation else {
        self.startLocation = loc
        return
    }
    guard let current = manager.location else { return }

    let distance = current.distance(from: startLocation)
    print("Distance: \((distance))")
}

0 个答案:

没有答案
相关问题