您好,我无法显示自动完成功能,如 here 。我的代码可以在提交时正常工作并正确显示 map ,但不显示自动完成的结果。我想知道可能是什么问题。
这是我的 HTML
<div id="floating-panel">
//this is the text field that does not display the autocomplete
<input id="address" placeholder="Enter Starting Location" type="text"/>
<input id="submit" type="button" value="Directions">
</div>
<div id="right-panel"></div>
<div id="map"></div>
这是我的 JavaScript:
var autocomplete = new google.maps.places.Autocomplete(document.getElementById('address'));
这是我对自动完成的调用,API 已启用,我看到正在对数据进行调用,但没有返回结果:
https://maps.googleapis.com/maps/api/js?key=xxx&libraries=places&callback=initMap: {type: external, attributes: {async: true}}
最佳答案
Google map API 在新版本中有新的安全更改,使用 3.0 版,这对我有用:
<script src="https://maps.googleapis.com/maps/api/js?v=3.0&key=YOUR_KEY&libraries=places" async></script>
关于javascript - 自动完成 Google Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49055809/