我正在Google地方信息自动填充功能中使用componentRestrictions
。我可以按国家限制,但是当我试图通过行政区域限制时,整个事情都会崩溃。
var options = {
componentRestrictions: { administrativeArea: 'TX' }
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
}
});