Home    Articles

 

Google Autocomplete how to get GPS coordinates for place or address

 

If you are trying to get GPS coordinates of some address that you've founded in the Autocomplete script, here is how you get them:

1. Take this google example:

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

2. Find the function and edit: 

Find this function: fillInAddress and add these lines: 

// [START region_fillform]
function fillInAddress() {
  // Get the place details from the autocomplete object.
  var place = autocomplete.getPlace();
  // this will show you in console the coordinates
  console.log(place.geometry.location.lat());
  console.log(place.geometry.location.lng());
.....
}

The GPS coordinates are there, you just need to know to find them.

UPDATE: Google has updated this API so you should take a look at features and deprechated things.

Enjoy.

by