How do I get Google Maps "Places API" to return ZIP code information? In all the examples I find on the internet, none of them show results returning that contain a ZIP code. Is there a trick to this or is it not possible?
Just query the geocode API with the following string "zip XXXXX" and if you have a valid zip, they will send you back the lat/lon and more.
Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.
Google Maps has added a feature where it will highlight in a pink color the borders of a city, postal code or other borders based on your search. To see it yourself, go to Google Maps and search for a city name or even a zip code. You will see a pinkish highlight around the border.
Go to the Google Cloud Console. Click the Select a project button, then select the same project you set up for the Maps JavaScript API and click Open. From the list of APIs on the Dashboard, look for Places API. If you see the API in the list, you're all set.
This seems like it's returning a "postal code" (4 digits for some reason) in the address_component
section:
https://developers.google.com/places/documentation/#PlaceDetailsRequests
However, I think what you're looking for is the Google Geocoding API:
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. The Google Geocoding API provides a direct way to access a geocoder via an HTTP request. Additionally, the service allows you to perform the converse operation (turning coordinates into addresses); this process is known as "reverse geocoding."
You can see in the JSON and XML responses a 5-digit postal code:
https://developers.google.com/maps/documentation/geocoding/#JSON
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With