以 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/