Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Google Maps "Places API" to return ZIP code information?

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?

like image 582
djangofan Avatar asked Aug 04 '12 03:08

djangofan


People also ask

How can I get Google Map API zip code?

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.

How do I get data from Google Maps places API?

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.

Can Google Maps show zip codes?

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.

How do I use Google Places Autocomplete API?

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.


1 Answers

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

like image 191
Alex W Avatar answered Sep 21 '22 15:09

Alex W