Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get 9 digit zip code from 5 digit zip code, programmatic, api

I have 5 digit zip codes, these are retrieved from Google Maps Api.

My dilemma is that I have to connect to a remote database which also contains addresses. If the address does not exist in that database, I have to write it, if it does exist then I do nothing except store the ID that database has assigned to the address. The problem arises since the api to check this database does not take wildcards, the addresses in that database have 9 digit zip codes (5+4) and will not return that the rest of the address matches my address with 5 digit zip codes.

The remote system will tell me that the address does not exist with the ones I send it.

So to prevent duplicate addresses from being written to the database I would need to find the 9 digit version of the zip code I have before sending it.

How would this be done? Is there a formula for determining what the last 4 digits of a 5 digit address are? Does the USPS have an API? Does the Census have a giant table?

Insight appreciated

like image 273
CQM Avatar asked Feb 22 '13 21:02

CQM


People also ask

How do you format a 9-digit ZIP Code?

The 9-digit ZIP Code consists of two sections. The first five digits indicate the destination post office or delivery area. The last 4 digits represent specific delivery routes within delivery areas.

How many 5 − digit ZIP codes are possible from 0 9 i If digit can be repeated?

1 Expert Answer There are ten possible digits (0 to 9). This means 100000 possible zip codes if repeatable. 540 * 56 = 30240 zip codes without any repetitions.

Why are there 9 digits in a ZIP Code?

So, USPS created 9-digit ZIP Codes to ensure fast and accurate mailings. They indicate the actual path the mail should travel and usually they narrow down to somewhere between ten to twenty homes.

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.


2 Answers

You are only allowed to use the USPS API for information if you are using the USPS to send out mail...

But you could check out SmartyStreets (I used to work there) or another CASS-Certified vendor. They are licensed for address verification, and you can also perform city-state and ZIP code lookups without an address (depending on who you choose).

I think you'll find them much easier and more comprehensive than the default USPS web service.

Here's some sample code... take your pick: https://github.com/smartystreets/LiveAddressSamples

like image 91
Matt Avatar answered Nov 15 '22 11:11

Matt


The US Postal Service have a number of APIs. Their "Address Information APIs" include:

Address Standardization

Eliminate addressing errors and help ensure accurate and timely delivery. This tool corrects errors in street addresses, including abbreviations and missing information. It also supplies a ZIP+4® Code.

ZIP Code™ Lookup

Find matching ZIP Codes or ZIP+4 Codes for any given address, city, and state in the U.S.

City/State Lookup

Use a ZIP Code to get accurate city and state information.

The Address Information APIs require permission to use.

like image 43
Martey Avatar answered Nov 15 '22 09:11

Martey