将componentRestrictions仅用于Google地图中的一个州

时间:2014-10-22 15:17:46

标签: google-maps

我正在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(' ');
    }

});

1 个答案:

答案 0 :(得分:2)

恐怕你不能,因为Google Maps only accept country as a filer