How to reproduce the issue:
on this page https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
choose some address, for example 20 Water Street, New York City, NY, United States
, (as expected the fields are being filled with the info). Now, e.g. in address change 20 to 10, and instead of choosing the address from the suggested list, just click somewhere on the page. The suggested list disappears, the new address 10 Water Street, New York City, NY, United States
remains in the input field, but the fields information is not being updated.
I am using this to get the latitude and longitude. So, if the user instead of clicking on the address, clicks outside, it will look like, that he changed the address, but in fact I still will have the previous address's Lat and Lng.
here is the init function
var autocomplete;
function initialize() {
autocomplete = new google.maps.places.Autocomplete(
/** @type {HTMLInputElement} */
(document.getElementById('addressAutocomplete')), {
types : [ 'geocode' ]
});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
console.log(place);
});
}
I was thinking smth like this can work, but it does not, this line console.log(place);
outputs undefined
$(document).ready(function() {
$(document).on('focusout', '#addressAutocomplete', function() {
google.maps.event.trigger(autocomplete, 'place_changed', {});
});
});
Thanks