根据Google Maps API docs,您可以使用指定为IANA language region subtag的区域代码来偏置结果。在查看第二个链接时,您会看到欧洲有一个欧盟区域子标签,该标签已于2009-07-29添加。但是,下面的两个代码示例中没有一个似乎遵循这种偏见。当我对地理编码" Hoboken"我在美国得到Hoboken,而不是在比利时,欧盟的Hobken。
geocoder.geocode( { 'address': address, 'region': 'EU'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results[0].geometry.location);
}
else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
或在网址中使用区域parementer:
<script src="http://maps.google.com/maps/api/js?sensor=false&region=EU"></script>
答案 0 :(得分:0)
使用组件限制,这些限制将搜索限制为指定的参数。
Geocoder组件限制定义如下:
componentRestrictions: {
country: 'BE'
}
所以你的电话现在是:
geocoder.geocode( { 'address': address, 'region': 'EU', componentRestrictions: {
country: 'BE'
}
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results[0].geometry.location);
}
else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
此处有更多信息:https://developers.google.com/maps/documentation/javascript/reference#GeocoderComponentRestrictions