Reputation: 153
I am having a problem with the place_changed event not firing when I click on an item in the drop down. If I right-click an item then it fires. If I left-click then it will sometimes fire, but only about 10% of the time.
I have looked to see if there are any listeners that might be interfering, but I am not seeing any. If I trace into the Google maps code I can see that a click event seems to be firing, but it doesn't detect a change in the location field so the place_changed is not fired. So something seems to be preventing the location value from being set.
Here is the code where the autocomplete is set and the listener is set.
function initAnyGoogleAutocomplete(searchBoxElementId, placeChangedCallbackFunction) {
google.maps.event.clearListeners(document.getElementById(searchBoxElementId), 'place_changed');
var searchBoxReferenceVar = new google.maps.places.Autocomplete(document.getElementById(searchBoxElementId),
{
bounds: map.getBounds(),
componentRestrictions: {country: 'us'}
});
google.maps.event.addListener(searchBoxReferenceVar, 'place_changed', placeChangedCallbackFunction);
return searchBoxReferenceVar;
}
Upvotes: 2
Views: 2048
Reputation: 153
I finally discovered the cause of the issue. The body was set to draggable and the drag event was bound to a function that returned false. That event was interfering with the location within the autocomplete from being set.
Upvotes: 1