简体   繁体   English

Google Maps API:如何仅将街道地址作为自动填充的结果

[英]Google Maps API: How to get street addresses only as results of Autocomplete

Given the bounds of a specific city in the form of a google.maps.LatLngBounds type variable, I want to get street addresses from that specific area as results of the autocomplete feature. 考虑到google.maps.LatLngBounds类型变量形式的特定城市的界限,我想从该特定区域获取街道地址作为自动完成功能的结果。

I read that using bounds in Google Maps API gives only approximate results and that would work for me. 我读到使用Google Maps API中的边界仅提供近似结果,这对我有用。 Problem is: at the moment results are not even close to the specified area. 问题是:此刻结果甚至不接近指定区域。

<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();
})

What I am getting are both city names and addresses with no restrictions at all. 我得到的是城市名称和地址,没有任何限制。 I already checked the variable event_city_bounds and it always contains the correct bounds of any city I previously select (from another input menu). 我已经检查了变量event_city_bounds ,它总是包含我之前选择的任何城市的正确边界(来自另一个输入菜单)。 Hope someone can help. 希望有人能提供帮助。

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. 通常,当您知道用户将查找完全指定的地址时,您将使用此请求。

So you can try something like this 所以你可以尝试这样的事情

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM