I have an app that currently fires correctly on place_changed.
However, I want to branch search to behave differently when a user has selected an autocomplete entry,
This comes down to checking whether you receive a place.geometry
object, as it is shown in their official example. As simple as that!
function initialize() {
var ac = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')), {
types: ['geocode']
});
ac.addListener('place_changed', function() {
var place = ac.getPlace();
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
// Do anything you like with what was entered in the ac field.
console.log('You entered: ' + place.name);
return;
}
console.log('You selected: ' + place.formatted_address);
});
}
initialize();
#autocomplete {
width: 300px;
}