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

问题描述 投票:0回答:1

我目前正在开发一个IOS项目,我必须计算两个位置之间的距离。我没有使用谷歌,但我想使用谷歌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)!)
ios swift google-maps geolocation geocoding
1个回答
1
投票

使用CoreLocation Framework的距离函数,

 var startLocation = CLLocation(latitude: startLatitude, longitude: startLongitude)
 var endLocation = CLLocation(latitude: endLatitude, longitude: endLongitude)
 var distance: CLLocationDistance = startLocation.distance(from: endLocation)
© www.soinside.com 2019 - 2024. All rights reserved.