'google.maps.event.addDomListener() is deprecated, use the standard addEventListener() method instead : Google Place autocomplete Error
I am trying to add Google place auto suggest, I copied the code from the developer's website to try it out but got the error : google.maps.event.addDomListener() is deprecated, use the standard addEventListener() method instead. Also I am not getting any place suggestions.
https://developers.google.com/maps/documentation/javascript/places-autocomplete
google.maps.event.addDomListener(window, 'load', initializeAutocomplete);
i have also added script
<script src="https://maps.googleapis.com/maps/api/jskey=api_key&libraries=places"></script>
I have implemented the same thing in one html it worked successfully, but when I used it on click button which opens a popup (form which has place-input), it gave me this error.
Note : I have also tried addEventListener but that's giving me an error : google.maps.event.addEventListener is not a function
Do you have any idea why I am getting this error, and how can I fix this?
Solution 1:[1]
As addDomListener() is deprecated, use the standard addEventListener() method instead, you can do so as follows:
window.addEventListener('load', initializeAutocomplete)
Replace in a similar fashion at all the required places.
google.maps.event.addDomListener(<OBJECT>,<EVENT>,<FUNCTION>);
to
<OBJECT>.addEventListener(<EVENT>,<FUNCTION>);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | poo |