Your code snippet appears to assume that the Postal Code is always at array position 5. Instead, you need to scan through the array examining results[0].address_components[i].types, to find "postal_code," which may be at differing values of "i". (same for type "street_number", "route", "locality,political", etc.)
If that isn't your problem, then your problem is likely to be elsewhere than in your snippet. That's why you are asked (in the posting guidelines) to post a link to a (nearly) working version. You are more likely to get useful help that way. - Jeff On Jun 1, 11:09 pm, jesar james <[email protected]> wrote: > Can anyone teach me how to use "types[]" and "address_components[]"? > Because I'm having a hard time retrieving address information with my > code. > > // Display Street Address > document.getElementById('txtStreet').value = > results[0].address_components[1].long_name+" > "+results[0].address_components[2].long_name; > // Display City > document.getElementById('txtCity').value = > results[0].address_components[3].long_name; > // Display Country > document.getElementById('txtCountry').value = > results[0].address_components[4].long_name; > // Display Postal Code / ZIP > document.getElementById('txtPostal').value = > results[0].address_components[5].long_name; > > Thank you! -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
