Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places Autocomplete - how to get Latitude and Longitude?

I use URL:

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

What should I do to retrieve data with places location (Latitude and Longitude)?

like image 454
Bartłomiej Semańczyk Avatar asked Dec 30 '14 12:12

Bartłomiej Semańczyk


People also ask

How do I find the latitude and longitude of Google autocomplete?

Getting latitude and longitude Wen the user has selected a place we can get the latitude and longitude by calling lat() and lng() on the place object.

How do I get lat long from Google Places API?

You could use place. geometry. location. lat() and place.


1 Answers

It is not possible ONLY with this URL:

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

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

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

Where:

PLACE_ID - retrieved place_id from previous request.

API_KEY - my key generated by Google to use with my app.

autocomplete must be replaced with details in above URL's.

like image 140
Bartłomiej Semańczyk Avatar answered Oct 18 '22 20:10

Bartłomiej Semańczyk