A Mohammed Hussain
A Mohammed Hussain

Reputation: 245

Get zipcode with geo-autocomplete in google api v3

This is the code I am using: https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete

When I select an address in the geo-autocomplete textfield, I want the corresponding zipcode to appear in another textfield, is this possible? I would be glad if someone can help me reach a solution.

After doing some research I found this:

var zip = address[address.length - 1].long_name = results[0].address_components;

But I am confused with how to use this code to get the zipcode?

Thanks!

Upvotes: 1

Views: 8439

Answers (1)

geocodezip
geocodezip

Reputation: 161334

Looks to me like:

  1. there is not necessarily always a postal code in that response.
  2. if there is one, the best way to get it is to search through the address_components of the result looking for one with the type "postal_code" and use that, like this example

Upvotes: 5

Related Questions