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

时间:2017-12-27 12:02:04

标签: ios google-maps autocomplete distance

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

Plz have a look on this image for further clarification

1 个答案:

答案 0 :(得分: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)