

- #Us zip code lookup by city how to#
- #Us zip code lookup by city update#
- #Us zip code lookup by city full#
- #Us zip code lookup by city free#
What about ZIP codes that encompass multiple cities? These are more common than I would have believed. The form will now automatically fill in your city and state fields once the zip code field is filled in. This example assumes you are using jQuery.

We will use that response to pre-fill the city and state fields. We can use javascript to watch for a change on the ZIP code field, and make a request to Google’s API to find out the city and state. Let’s start with the basic HTML form: Add a bit of Javascript How can we utilize Google’s Geocode API response to pre-populate an address form?
#Us zip code lookup by city how to#
If you want an example of how to use this data to actually fill in a form, read on. If you are comfortable with parsing JSON, you probably have found what you were looking for. You can read more about the many features of Google’s geocoding API on their documentation page. The request format is: ZIP_CODE&key= YOUR_API_KEY will, and in the response you get a lot of information, including for our purposes, that 92101 is the postal code for San Diego, California.

You can pass in all kinds of data in the address field, so be sure to read the documentation, but simply passing the ZIP code gives us what we need. The request is actually very simple once we have an API key. In order to get the city and state based off a ZIP code, we are going to want to use Google’s Geocoding API. There are still other valid reasons to look up city/state using ZIP code, and if you have one, read on.
#Us zip code lookup by city full#
For information on setting up an API key visit the Google Cloud Platform.Įditor’s Note: This post was first published in 2016, since then Google has released the Places Autocomplete API, which would be a more appropriate use-case for pre-filling a full address form.
#Us zip code lookup by city free#
The geocoding api has a generous free tier, but it is not unlimited.
#Us zip code lookup by city update#
Update 2021: Google now requires an API key for geocode lookups. In this post I will show you how to use Google Maps APIs to take a ZIP code and turn it into a city and state. ** or equivalent province, district, etc.Have you ever come across a web form which asks for your ZIP code and then pre-fills your city and state in for you? I love these types of seemingly small interactions which can end up saving people time and remove some human error. * You can also type in GPS coordinates in decimal degrees into the Search places box.

Enter the address, city, state, province, or country into the search field above to locate a mailing address or find a package’s origin.
