我在将 componentRestrictions 参数添加到 Google Maps Geocoder 对象时遇到问题。我正在使用 JavaScript 客户端 api。具体来说,该administrativeArea
物业不适合我。文档说 type 是一个字符串,我尝试了很多组合但仍然没有运气。
这是我的地理编码功能:
function geocodeAddress(geocoder, resultsMap) {
var address = document.getElementById('address').value;
geocoder.geocode({'address': address, 'componentRestrictions': {administrativeArea: 'Maricopa County'}}, function(results, status) {
if (status === 'OK') {
resultsMap.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
console.log(results)
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
我可以让其他 componentRestriction 属性工作,比如postalCode
and country
,但不是administrativeArea
。文档说该属性匹配所有的administrative_area levels
,所以我尝试使用不同的美国县和不同的美国州,但无法让它工作。我想我的语法错误,任何帮助将不胜感激!