I'm using Google Maps' autocomplete feature for geocoding. It seems to return a lot of data, but not the lat/lng. Is there a way to get this information? I'd like to pass it back to my backend application for further processing.
You could use place. geometry. location. lat() and place.
You can use the Google API to get the Longitude and Latitude from your address. As you already said, you should implement a hidden field where the result should be inserted. Then you can save the location together with the coordinates. Save this answer.
There are methods called lat() and lng() that exist on the geometry object's prototype. So to get the values, just use the following:
var place = autocomplete.getPlace(); var lat = place.geometry.location.lat(), lng = place.geometry.location.lng(); // Then do whatever you want with them console.log(lat); console.log(lng); console.warn('Warning: I didn\'t test this code!');
OK, I'm not familiar with Places or Autocomplete. But it looks like what you are looking for is
autocomplete.getPlace().geometry.location
To demonstrate I took this example and added the line above to create this JSFiddle where you can enter the place name and when it's selected, an infowindow with the LatLng is created.
In particular it listens to the user's selection, then refreshes the infowindow.
google.maps.event.addListener(autocomplete, 'place_changed', function() { infowindow.close(); var place = autocomplete.getPlace(); ... infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address + "<br>" + place.geometry.location);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With