如何根据Google地图自动填充地址api中的国家/地区和城市过滤地址。 我能够根据国家解决过滤器,但我无法根据国家和城市解决过滤器问题。我使用以下代码: -
var autocompleteFrom;
$(document).ready(function () {
var options = {
types: ['geocode'],
componentRestrictions: { country: "IL" }
};
var inputFrom = document.getElementById('Address');
autocompleteFrom = new google.maps.places.Autocomplete(inputFrom, options);
google.maps.event.addListener(autocompleteFrom, 'place_changed', fillAddrss);
});
答案 0 :(得分:2)
目前无法将城市过滤器应用于自动填充。
Google问题跟踪器中有一个feature request可以实现此目的。但是我们在那里看不到任何ETA。
我可以建议您查看功能请求以添加投票并从Google接收更新。
作为一种解决方法,您可以使用strictBounds参数定义城市边界并按城市边界过滤结果
var options = {
bounds: cityBounds,
strictBounds: true,
types: ['geocode'],
componentRestrictions: { country: "IL" }
};
有关详细信息,请参阅文档:
https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions