mardi 17 février 2015

Google Maps API JS - Place autocomplete with two combined fields

I come to you because I can not use the autocomplete place function instead of Google maps JS api v3 as I would like.


Indeed, I would like to implement autocompletion on a field by adding the value of another.


Concretely, I would like to have two fields, one for the company name, the other for the address. I would like autocompletion is performed only on the address fields but taking into consideration the company name.


Classical example with one input :


Function JS :



function initialize() {
// Create the autocomplete object, restricting the search
// to geographical location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {HTMLInputElement} */(document.getElementById('addr')),
{ types: ['establishment', 'geocode'] });
// When the user selects an address from the dropdown,
// populate the address fields in the form.
google.maps.event.addListener(autocomplete, 'place_changed', function() {
fillInAddress();
});
}


HTML Form :



<input class="field" id="company_name" />
<input class="field" id="addr" />


In your opinion is it possible? If so, how?


With thanks.





Aucun commentaire:

Enregistrer un commentaire