从当前位置IOS查找自动完成结果位置的距离

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

我正在开发像Uber和Careem这样的应用程序。当用户使用Google商家信息自动填充API搜索某个位置时,我想显示距离以及自动完成的名称,例如Uber和Careem会这样做。

Plz have a look on this image for further clarification

ios google-maps autocomplete distance
1个回答
0
投票

编辑:

其中cuGMS是GMSAutocompletePrediction的数组

        let cuGMS = self.resultsArray[indexPath.row]

        let placesClient = GMSPlacesClient()

        placesClient.lookUpPlaceID(cuGMS.placeID!, callback: { (response  , error) in

            print("response \(response)")

            if(error == nil)
            { 
                  let coor = response?.coordinate

                  let lat = coor?.latitude

                  let lon = coor?.longitude
            }
            else
            {

            }

        })

试试这个

    let loc1:CLLocation = CLLocation.init(latitude: 30.0000, longitude:29.2545)

    let loc2:CLLocation = CLLocation.init(latitude: 28.02002, longitude:27.00021)

    let dis = loc1.distance(from: loc2)
© www.soinside.com 2019 - 2024. All rights reserved.