When a user adds an apartment number to his address, autocomplete seems to look at zipcode and change the proposed matches:
6250 Hollywood Blvd No. 20
Is there a way to make this work, and if not, a way to ignore the apartment number and send it along with submitting the form as a separate value? (bearing in mind that the user can use #, Unit, Apt, etc. to determine their device number)
var placeSearch, autocomplete; var componentForm = { street_number: 'short_name', route: 'short_name', locality: 'long_name', administrative_area_level_1: 'short_name', country: 'long_name', postal_code: 'short_name' }; function initialize(){ autocomplete = new google.maps.places.Autocomplete( (document.getElementById('autocomplete-address')), { types: ['geocode'] }); google.maps.event.addListener(autocomplete, 'place_changed', function(){ fillInAddress(); } ); } function fillInAddress(){ var place = autocomplete.getPlace(); for(var component in componentForm){ document.getElementById(component).value = ''; document.getElementById(component).disabled = false; } for(var i = 0; i < place.address_components.length; i++){ var addressType = place.address_components[i].types[0]; if(componentForm[addressType]){ var val = place.address_components[i][componentForm[addressType]]; document.getElementById(addressType).value = val; } } }
source share