自动完成Google Javascript [英] AutoComplete Google Javascript

查看:105
本文介绍了自动完成Google Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我无法让自动填充显示如此处。我的代码适用于提交并正确显示地图,但不显示自动填充结果。我想知道可能是什么问题。

这是我的HTML

 < div id =floating-panel> 

//这是不显示自动完成的文本字段
< input id =addressplaceholder =Enter Starting Locationtype =text/>

< input id =submittype =buttonvalue =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}} 


解决方案

谷歌地图API在其新版本中使用了新的安全更改,使用3.0版本,这对我很有用:

 < script src =https://maps.googleapis.com/maps/api/js?v=3.0&key=YOUR_KEY&libraries=placesasync>< / script> 


Hi I am having trouble getting the autocomplete to display like here. My code works on submit and displays the map properly, but does not show results of autocomplete. I am wondering what could be the issue.

Here is my 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>

Here is my Javascript:

 var autocomplete = new google.maps.places.Autocomplete(document.getElementById('address'));

Here is my call to autocomplete, the API is enabled, I see calls being made on the data, but no results back:

 https://maps.googleapis.com/maps/api/js?key=xxx&libraries=places&callback=initMap: {type: external, attributes: {async: true}}

解决方案

Google maps API has new security changes in its new version, use version 3.0, this works for me:

<script src="https://maps.googleapis.com/maps/api/js?v=3.0&key=YOUR_KEY&libraries=places" async></script>

这篇关于自动完成Google Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆