如何使用 google api in swift 计算两个位置之间的距离 4

How to calculate distance between two locations using google api in swift 4

我目前正在做一个 IOS 项目,在这个项目中我必须计算两个位置之间的距离。我没有使用 google 但我想使用 google api 来获得准确的距离我在这里分享我的代码

    let myLocation = CLLocation(latitude: CLLocationDegrees(latittude[indexPath.row])!, longitude: CLLocationDegrees(longittude[indexPath.row])!)
        let lat = UserDefaults.standard.string(forKey: "lat") ?? ""
        let long = UserDefaults.standard.string(forKey: "long") ?? ""
        let myBuddysLocation = CLLocation(latitude: CLLocationDegrees(lat)!, longitude: CLLocationDegrees(long)!)

使用CoreLocation框架的距离功能,

 var startLocation = CLLocation(latitude: startLatitude, longitude: startLongitude)
 var endLocation = CLLocation(latitude: endLatitude, longitude: endLongitude)
 var distance: CLLocationDistance = startLocation.distance(from: endLocation)