Google商家信息自动填充功能 - 如何获得纬度和经度?

Bar*_*zyk 6 autocomplete ios google-places-api

我使用URL:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=bar&key=API_KEY&types=geocode
Run Code Online (Sandbox Code Playgroud)

如何使用地点位置(纬度和经度)检索数据?

Bar*_*zyk 21

仅使用此URL不可能:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=bar&key=API_KEY
Run Code Online (Sandbox Code Playgroud)

我需要做的就是place_id从响应中获取,然后在下面的URL中使用它:

https://maps.googleapis.com/maps/api/place/details/json?input=bar&placeid=PLACE_ID&key=API_KEY
Run Code Online (Sandbox Code Playgroud)

哪里:

PLACE_ID - place_id从先前的请求中检索.

API_KEY - Google生成的密钥,用于我的应用.

autocomplete必须details在上面的URL中替换.


Azh*_*har 5

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=bar&key=API_KEY
Run Code Online (Sandbox Code Playgroud)

然后获取place_id并调用以下函数以获取数据

let placesClient = GMSPlacesClient.shared()
    func GetPlaceDataByPlaceID(pPlaceID: String)
    {
      //  pPlaceID = "ChIJXbmAjccVrjsRlf31U1ZGpDM"
        self.placesClient.lookUpPlaceID(pPlaceID, callback: { (place, error) -> Void in

            if let error = error {
                print("lookup place id query error: \(error.localizedDescription)")
                return
            }

            if let place = place {
                print("Place name \(place.name)")
                print("Place address \(place.formattedAddress!)")
                print("Place placeID \(place.placeID)")
                print("Place attributions \(place.attributions)")
                print("\(place.coordinate.latitude)")
                print("\(place.coordinate.longitude)")
            } else {
                print("No place details for \(pPlaceID)")
            }
        })
    }
Run Code Online (Sandbox Code Playgroud)