2016-03-07 27 views
0

尝试没有地图与谷歌自动完成工作,但它是麻烦。限制谷歌自动完成的邮政编码

<script> 
    var autocomplete; 
    var countryRestrict = {country: 'NO', postalCode: '0365'} 
    function initAutocomplete() { 
    autocomplete = new google.maps.places.Autocomplete(
     (document.getElementById('address-field')), 
     { types: ['address'], 
     componentRestrictions: countryRestrict 
     }); 
    } 
</script> 
<script src="https://maps.googleapis.com/maps/api/js?key=API-KEY&libraries=places&callback=initAutocomplete" 
     async defer></script> 

当我添加postalCode到countryRestrict它停止工作,但我自己的例子中看到,他们似乎要限制其使用的例子:

componentRestrictions: {country: "AU", postalCode: "2000"} 

https://developers.google.com/maps/documentation/javascript/examples/geocoding-component-restriction

是它我能够限制地址自动完成给定的邮政编码?

回答

2

目前,它是不可能的,一个Autocomplete唯一支持componentRestriction是country (链接的例子是地理编码,其中更componentRestrictions支持的实现)

添加其他componentRestrictions比支持的选项导致脚本 - 错误打破了自动完成

+0

好吗,谢谢,我认为有可能是过滤掉任何结果(通过不显示他们),如果他们不属于该职位代码的方式,你知道的任何例子,在那里,可能会这样做? –

+0

当您看到下拉菜单时,建议地点的详细信息(包括邮编)不可用,所以在请求详细信息之前(从下拉菜单中选择地点)之前无法过滤任何东西。 –

+0

我正在考虑做 –

相关问题