我有我的形式是使用谷歌的自动完成功能上的场
new window.google.maps.places.Autocomplete(location, { types: ['geocode'] });
但是,如果用户不选择从自动完成下拉我需要谷歌地图的地理编码器提交表单时进行搜索。我想我的用户在世界选择一个街道,镇,市,街道等任何地方!
var navbarGeocoder = new google.maps.Geocoder();
navbarGeocoder.geocode({
'address': location.value
}, function(results, status) {
但现在我希望能够限制地理编码美国(街道,居委会,市,镇等)与该国的componentRestriction(美国),但是当我尝试这下面它只是挂起!
var navbarGeocoder = new google.maps.Geocoder();
navbarGeocoder.geocode({
'address': location.value
}, {
componentRestrictions: {
country: ' US'
}
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
// do something
} else {
// do something
}
});
是否有添加成分的限制,仍然有地址字段有道?任何帮助,将不胜感激!
我使用这个link到谷歌网站的文档,有没有它如同地址场中的元件的限制领域?
从寻找您所提供的文件在我认为你的问题实际上可能是非常简单 - 虽然我还没有测试它自己。无论如何,如果你向上滚动到“地址解析请求”部分中,您会看到下面的代码。
{
address: string,
location: LatLng,
placeId: string,
bounds: LatLngBounds,
componentRestrictions: GeocoderComponentRestrictions,
region: string
}
所以,我觉得你只是需要把componentRestrictions场在同一个阵列的实际地址英寸让我知道,如果它可以帮助:)
因此,而不是你贴什么,试试这个...
var navbarGeocoder = new google.maps.Geocoder();
navbarGeocoder.geocode({
'address': location.value,
componentRestrictions: {
country: ' US'
}
},
我想到了。
下面是代码片段!
navbarGeocoder.geocode({
address: location.value,
componentRestrictions: {
country: ' US'
}
}, function(results, status) {