在创建对象时添加对自动完成的限制。
var options = {
types: ['geocode'],
componentRestrictions: {country: "IN"}
};
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')),
options);
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
随着国家价值的变化
options.componentRestrictions.country