首页 > 解决方案 > 当前位置和更新位置之间的距离

问题描述

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

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

那么,如何跟踪用户位置并测量当前位置与用户更新位置之间的距离

我尝试了此代码,但该措施不正确。

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))")
}

标签: swiftlocationcllocationmanager

解决方案


推荐阅读