Google Places AutoComplete - How do I get latitude and longitude?

I am using the URL:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=bar&key=API_KEY&types=geocode 

What to do to retrieve data with the location of places (latitude and longitude)?

+5
source share
3 answers

Impossible ONLY with this URL:

 https://maps.googleapis.com/maps/api/place/autocomplete/json?input=bar&key=API_KEY 

All I had to do was get the place_id from the response, and then use it in the following URL:

 https://maps.googleapis.com/maps/api/place/details/json?input=bar&placeid=PLACE_ID&key=API_KEY 

Where:

PLACE_ID - extracted place_id from the previous request.

API_KEY is my key created by Google for use with my application.

autocomplete should be replaced with details in the above URLs.

+18
source

This is actually called "Google Places AutoComplete," not "AutoComplete Maps." You get the id of the place from there, you need to call the Google api api to get information about the details, including locations, etc.

https://developers.google.com/places/documentation/details

Or you can use the Place Search api as your needs.

https://developers.google.com/places/documentation/search

+2
source
 https://maps.googleapis.com/maps/api/place/autocomplete/json?input=bar&key=API_KEY 

Then get place_id and call the following function to get the data

 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)") } }) } 
0
source

Source: https://habr.com/ru/post/1210103/


All Articles