Change the value in textbox of a google map autocomplete

后端 未结 4 1433
温柔的废话
温柔的废话 2021-01-05 13:06

I have the following javascript code which does google map autocomplete on different input textboxes that are parts of an address.

function startAutoComplete         


        
4条回答
  •  星月不相逢
    2021-01-05 13:48

    The simplest way I've found to programmatically change the value of an Autocomplete input is to reinitialize the input field.

    autocomplete = new google.maps.places.Autocomplete(address, option);
    
    google.maps.event.addListener(autocomplete, 'place_changed', function() {
       // populate your other text fields
       ...
       // change the value of your autocomplete
       address.value = place.name;
       // reinitialize with new input value
       autocomplete = new google.maps.places.Autocomplete(address, option);
    }
    

提交回复
热议问题