考虑到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']});