I tried to find a solution only for this issue without success. So i will appreciate your help.
I would like to get autocomplete address from google api. I'm using this code now:
var input, options, zip;
$( document ).ready(function() {
options = {
types: ['address'],
componentRestrictions: {
'country': 'IT'
}
};
zip = $('#residence_zip');
input = document.getElementById('autocomplete');
initAutocomplete();
});
function initAutocomplete() {
var autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.addListener('place_changed', function () {
var element = $(autocomplete.getPlace().adr_address);
var cap = jQuery(element[2]).text();
zip.val(cap);
});
}
It works well! but i would like to add a filter by city name. I'm trying like this:
options = {
types: ['address'],
componentRestrictions: {
'country': 'IT', 'locality': 'Roma'
}
};
But it doesn't work. :(