简体   繁体   中英

Google Places autocomplete and search not working

Google places autocomplete dropdown is not populating any places and when I click on search i am getting this below error.

But if I do keyboard ENTER - i see the results on the map.

Everything was working fine till yesterday and nothing changed in regards to code.

(index):9 Uncaught TypeError: Cannot set property 'handled' of undefined
    at _.Ec (js?key=AIzaSyDiIbcf012mobkCgUHnNjqRYzNCmTDeR1g&libraries=places:48)
    at HTMLInputElement. (js?key=AIzaSyDiIbcf012mobkCgUHnNjqRYzNCmTDeR1g&libraries=places:49)
    at Object.trigger (js?key=AIzaSyDiIbcf012mobkCgUHnNjqRYzNCmTDeR1g&libraries=places:119)
    at HTMLButtonElement. ((index):2699)
    at HTMLButtonElement.dispatch (jquery.min.js:338)
    at HTMLButtonElement.elemData.handle (jquery.min.js:311)
    at HTMLButtonElement.nrWrapper ((index):9)

My search button also started failing with the same error. I think a API change somewhere between V3.31 and V3.34 made the final argument to event.trigger required instead of optional.

https://developers.google.com/maps/documentation/javascript/reference/event#event.trigger

My code looked like this:

button.click(function () {

    google.maps.event.trigger(input, 'focus');
    google.maps.event.trigger(input, 'keydown', {
        keyCode: 13
    });
});

I added an empty third argument to the focus trigger, like this:

google.maps.event.trigger(this, 'focus', {});

and everything started working again. Hope this helps anyone in a similar situation!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM