自动完成Google Javascript
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动完成Google Javascript相关的知识,希望对你有一定的参考价值。
嗨,我无法让自动完成显示像here。我的代码适用于提交并正确显示地图,但不显示自动完成的结果。我想知道可能是什么问题。
这是我的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}}
谷歌地图API在其新版本中有新的安全更改,使用版本3.0,这对我有用:
<script src="https://maps.googleapis.com/maps/api/js?v=3.0&key=YOUR_KEY&libraries=places" async></script>
我用相似的代码得到同样的东西。对我而言,代码工作了几个月,就在今天,我收到了一个用户的报告,显示位置下拉列表不再显示。
var input = $("input[name='location']");
var formattedAddress = input.next("input[name='formattedLocation']");
var searchBox = new google.maps.places.SearchBox(input[0]);
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
formattedAddress.val('');
return;
}
formattedAddress.val(places[0].formatted_address);
});
我在想,也许我们已经超过了我们的每日配额,但Google API控制台似乎并非如此。我没有在浏览器控制台中看到任何错误。如果我查看开发人员工具网络选项卡,我可以看到请求发送到https://maps.googleapis.com/maps/api/place/js/AutocompletionService.GetQueryPredictions,但响应看起来相当神秘(例如:/ ** / xdc._490z0c && xdc._490z0c([4]))所以我不知道是否好数据是否回归。
我想知道谷歌方面最近发生了一些我没有听说过的事情。
我的临时解决方案:我选择了经验版本https://maps.googleapis.com/maps/api/js?v=3.32
并注意到我的HTML底部有一个标签<div class="pac-container pac-logo hdpi">
once你开始输入更新,设计这个并修复。我发送了一个问题请求,我希望他们能为稳定版本修复此问题。
https://developers.google.com/maps/documentation/javascript/versions
如果您在标准计划中,请指定您要使用发布版本而不是实验版本。
以上是关于自动完成Google Javascript的主要内容,如果未能解决你的问题,请参考以下文章
在代码中获取地址自动完成(JavaScript API 的 Google Places 库)请求计数
具有自动完成功能的 Google Maps JavaScript API
无法从 Google Maps Javascript API 的自动完成中选择地址