简体   繁体   中英

Google Maps Places API: TypeError: autocomplete is undefined

Whenever I am trying to use the Google Maps API places library it gives me this error in the console of my browser:

TypeError: autocomplete is undefined

If I'm not mistaken, that means the places library couldn't load. As for the code, I had my own code but I also copypasted the code from the Places API tutorial( https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform ).

In my header I have these two lines included:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY_KEY_HERE"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

I also made sure Placis API, Google Maps JavaScript API v3 and Google Maps Geolocation API are all switched on in my Google APIs console.

I am not really sure what the problem is, besides the places library not loading. I should note I am working on a hidden subdomain, could that be the problem?

Thanks in Advance.

Please make sure you only load the maps file once (and you should always load the api via https, or with the active protocl):

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=MY_KEY_HERE&libraries=places&sensor=false"></script>

The subdomain should not be a problem, so you can work with it.

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