-2

I've been trying to figure out how google fills in the text inputs with precise data in their example after you entered an address in their example https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

I'm not very good a javascript but I can somewhat understand it but can't find anywhere in the code where they apply it to the input fields.

Any help is much appreciated

  • Welcome to Stack Overflow. Please consider revising your question to make sure that you provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) so that people are able to help you. Also, be sure to include *your own attempt* for the problem at hand. – Nick Zuber Dec 27 '15 at 18:58

1 Answers1

0

Took me a while to realize that

var componentForm = {
  street_number: 'short_name',
  route: 'long_name',
  locality: 'long_name',
  administrative_area_level_1: 'short_name',
  country: 'long_name',
  postal_code: 'short_name'
};
////////////////////////////////////////////////////////////////////////
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;
         }
     }
}

was the answer, they loop through the size of place.address_components, then compare it to componentForm and then add it ot the inputs.