Showing zip/postcode in Google Places autocomplete dropdown

autocompletegoogle-maps-api-3google-places-api

I have been experimenting with Google Places Autocomplete for use in a form, but can not figure out how to have the zipcode /postcode show in the autocomplete dropdown or selected input value.

The autocomplete value returned contains the zipcode, so I can extract it and insert it into the proper form input, but it doesn't show when the web visitor is entering their data.

The goal is to have a very simple form, name, address, phone, email and have all of the address specific inputs hidden (state, city, street, zip, etc).

My concern is, even though the correct data is being submitted with the form, if the web visitors don't see their zipcode, they will be concerned that they haven't sent in the complete address.

I have discovered that once you select the correct address and then go back to type in the zipcode, the API will insert the zip into the correct place and show it. But it won't show it when you initially enter the address.

Any ideas of an available option that would cause the zip to be shown initially?

Best Answer

But it won't show it when you initially enter the address

...because it's not available when you enter the address. The details for a prediction will be requested when you select an item, not when you type something. So the answer is simple: it's not possible.

What you can do: create your own autocomplete and populate it with data.

You'll first need to request the predictions via the autocompleteService and then request the details via PlacesService.getDetails()

Related Topic