Hussein Duvigneau
Hussein Duvigneau

Reputation: 541

Google Maps Autocomplete doesn't include postcodes in address search

For my current project, I have an address lookup for the user to enter an address. In its default state, its results are too ambiguous, and the lookup returns all locations even if it isn't actually an address (eg some of the locations in the list are an entire city or region).

Adding types: ['address'] to the query has solved this; Google now only responds with actual addresses instead of ambiguous regions, however this has lost us the ability to search via postcode, as these two fiddles demonstrate:

http://jsfiddle.net/yj6qvpsg/2/ will list entire cities and regions (bad), but you can still search for an address with a UK postcode (good).

http://jsfiddle.net/yj6qvpsg/1/ will only list addresses (good), but won't search UK postcodes (bad).

How do we get the best of both worlds? I tried playing around with eg, types: ['address', 'postal_code'], but had no luck...

Upvotes: 3

Views: 3038

Answers (2)

This came up as the top result for this question, but is massively outdated.

So for anyone looking for a more in-depth search, set Google's Autocomplete to geocode and you can search by:

  • Street name
  • District
  • Town
  • City
  • Postcode

Ace!

Upvotes: 1

Hussein Duvigneau
Hussein Duvigneau

Reputation: 541

So it turns out that it's only really in the UK that postcodes are tied to physical addresses at street level (you can literally give the house number and postcode as a complete and valid address), while in the rest of Europe a postcode represents a whole region, hence Google considers postcodes as regions throughout.

Maybe one day they'll make an exception for the UK, but in the mean time an alternative if you really need this feature is probably to look at something like: https://getaddress.io/ which might suck if like us your entire data structure is built to match Google's

Upvotes: 1

Related Questions