mtorn
mtorn

Reputation: 159

Google Geocode/Places API: search zip code - get addresses connected to it, possible?

So, another Google API question but I didn't find any threads for my needs. I'm trying to implement a basic zip code search with Google API in plain Javascript (tested both Geocode and Places with Autocomplete). User should be able to search on a specific zip code and get street names returned which are connected to that zip code (and simply choose the correct address).

I have no problems getting results back using either one of the APIs but I can't wrap my head around Googles documentation for it since nothing tells you if this is possible or not. I've tested a couple of different types to send in the options setting but none actually returns an array of addresses.

Been thinking if reverse geocoding would be a solution but seems a bit hacky and also would require multiple requests..

Simply out of ideas, any help appreciated.

  types: ['geocode'],
  componentRestrictions: { country: 'SE' }
}

let autocomplete;

function initialize() {
  autocomplete = new google.maps.places.Autocomplete(
  document.getElementById('postalCode'), options);
  autocomplete.setComponentRestrictions({'country': ['SE']})
  autocomplete.setFields(['address_component']);
  autocomplete.addListener('place_changed', fillInAddress);

}

Upvotes: 2

Views: 3096

Answers (1)

Angelica
Angelica

Reputation: 717

Please note that it is currently not supported for the Geocoding or Places API to show a list of addresses by zip code.

Places Autocomplete is designed to return place predictions based on the user input and perceived relevance. While the Geocoding API is designed to convert a single string address to coordinates and vice versa.

You can use this Geocoder tool to test this.

There is also a related feature request for this functionality, it's marked as Infeasible/Intended behavior but you can still star it to receive updates: https://issuetracker.google.com/issues/64769088

Starring the issue also provides valuable feedback on the importance of the issue to customers, and increases the issue's priority with the product engineering team.

Upvotes: 1

Related Questions