根据Documentation,我们可以在componentRestrictions中使用administrative_area_level_1,administrative_area_level_2等。
那么如何在下面的代码中分别将state和District添加为administrative_area_level_1和administrative_area_level_2?
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address,
'componentRestrictions':{'country':'india'}
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}