I'm using Google Autocomplete and want to put street number + route value to the input field after selecting necessary location. I'm using this code
let options = { types: ['address'] };
let autocomplete = new google.maps.places.Autocomplete(element, options);
autocomplete.addListener('place_changed', function () {
let place = autocomplete.getPlace();
let components = new AutoCompleteAddressComponent(place.address_components).parse();
/* getStreet is returning address_components.street_number.short_name
and address_components.route.long_name */
let streetName = components.getStreet().trim();
$(element).val(streetName);
});
And how this code is working:
- User it typing something in the input
- Google is suggesting location from where users are selecting necessary one
- Input is reflecting on the user action and putting data. For example
777 Brockton Avenue, Abington, MA, USA - After this
place_changedis firing and777 Brockton Avenue, Abington, MA, USAreplacing to777 Brockton Avenue
I don't like that 4-th point where users can see how data is replacing from long address to the short one.
Is there any way to show street number + route right after selecting location from the dropdown? I've tried to play with an Autocomplete method options by providing different types, but nothing helps me. I also need to get all data like country, state, city, post_code in the autocomplete.getPlace() object (I'm pre-filling these fields on the site).