javascript - 自动完成 Google Javascript

标签 javascript google-maps autocomplete google-places-api

您好,我无法显示自动完成功能,如 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/

相关文章:

javascript - 在 TypeScript 中增强自定义类型

javascript - 将 Select2 与 Jeditable 结合使用

javascript - Node 的通用日志记录,快速应用程序——最佳实践?

javascript - 我怎样才能改变这个盒子的大小? (CSS)

android - 在 Google map V2 中绘制多边形网格

ios - 添加 -ObjC 链接器标志构建失败

javascript - 自动完成文本字段

php - jQuery 自动完成 - 隐藏 php 请求页面内容

javascript - React-native 数组检查值是否存在

html - 在 webkit 中使用自动完成的输入中的 Sprites 消失