javascript - 谷歌地图 API : How to get street addresses only as results of Autocomplete

标签 javascript jquery google-maps google-maps-api-3 autocomplete

google.maps.LatLngBounds 类型变量的形式给出特定城市的边界,我想从该特定区域获取街道地址作为自动完成功能的结果。

我读到在 Google Maps API 中使用边界只能给出近似结果,这对我来说很管用。问题是:目前结果甚至没有接近指定区域。

<input type="text" class="event_form_input" id="event_address" name="event_address" placeholder="Address" value="">
var address_input = document.getElementById('event_address');
var address_autocomplete = new google.maps.places.Autocomplete(address_input,{bounds: event_city_bounds, types: ['geocode']});

address_autocomplete.addListener('place_changed', function(){               
                var event_address=address_autocomplete.getPlace();
})

我得到的是完全没有限制的城市名称和地址。我已经检查了变量 event_city_bounds,它始终包含我之前选择的任何城市的正确边界(从另一个输入菜单)。 希望有人能帮忙。

最佳答案

Types supported in place autocomplete requests :

address instructs the Place Autocomplete service to return only geocoding results with a precise address. Generally, you use this request when you know the user will be looking for a fully specified address.

所以你可以试试这样的东西

var address_autocomplete = new google.maps.places.Autocomplete(address_input,{bounds: event_city_bounds, types: ['address']});

关于javascript - 谷歌地图 API : How to get street addresses only as results of Autocomplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40106541/

相关文章:

java - Google Map Android API V2 中两个位置之间的行驶距离和旅行持续时间

javascript - 谷歌分析: Plotting week of year data with full date on x-axis and visits in y-axis

php - 使表格在排序时显示交替的颜色背景

javascript - 如何根据计算样式查找元素

javascript - HTML 数组上的淡入/淡出

javascript - 确保在动态更改 jquery 时加载图像

java - 如何从谷歌地图网址获取经纬度

php - 谷歌地图标记未显示在资源管理器或 Chrome 中

javascript - 在页面加载时显示第一个 div 并隐藏其他,然后在单击菜单项时显示其余部分

javascript - 在 javascript 中更改数组变量也会更改代码中较早点的数组值