【发布时间】:2018-09-04 00:56:38
【问题描述】:
我在将 componentRestrictions 参数添加到 Google Maps Geocoder 对象时遇到问题。我正在使用 JavaScript 客户端 api。具体来说,administrativeArea 属性对我不起作用。 Docs 说 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 和 country,但不是 administrativeArea。文档说该属性与所有administrative_area levels 匹配,所以我尝试使用不同的美国县和不同的美国州,但无法让它工作。我想我的语法错误,任何帮助将不胜感激!
【问题讨论】:
标签: google-maps google-maps-api-3 google-geocoding-api google-api-javascript-client