5 ms·
Unfortunately in some cases a zipcode is in fact not enough, as it's possible for a zipcode to spread across multiple towns. However, if you have a full 9 digit
by asnyder 15y ago
Unfortunately in some cases a zipcode is in fact not enough, as it's possible for a zipcode to spread across multiple towns. However, if you have a full 9 digit zipcode then you can in fact always determine. However, even if you can't always determine this information exactly, a zipcode should be enough to pre-populate these fields for you most of the time, and in those rare cases which they don't a choice can be presented of only those qualifying choices.
The USPS has a pretty decent API that should allow this relatively easily.
- lisper 15y agoFor example: 94062 can be either Woodside or Redwood City or Emerald Hills.
- csmeder 15y agoYup, here the USPS response to 94062 https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=2&companyName=&address1=&address2=&city=&state=Select&urbanCode=&postalCode=94062&zip= https://tools.usps.com/go/ZipLookupResultsAction!input.actio...
- draebek 15y agoNote that it says "the actual city in 94062 is REDWOOD CITY." The others are merely "acceptable." For mailing purposes, at least, I understand this to mean that the USPS would prefer you to address mail items to Redwood City, regardless of what administrative entity the recipient is in (e.g. Woodside). Of course, if you're using the information from this API for purposes other than mailing, such as providing an address for verification along with credit card processing, I suppose your processor won't like seeing Redwood City if the cardholder has Woodside on file.
- rblatz 15y agoI plugged in 45440, and it returns Dayton as the actual city, but Dayton is miles away. It returns a bunch of other cities as acceptable, but those are the ones that are actually located in that zip code. I'm curious as to what all of this returned data actually means.
- daspecster 15y agoThanks! I will be looking into this more. I'm aware of the 9digit zipcodes. I'll look into the USPS API. Also, I'll address the other comment below. That might answer some questions.
- BryanB55 15y agoMy only problem with 9 digit zip codes is that I have no idea what mine is. I know the first 5 but not the last 4. If you have multiple addresses or move around a lot its not something you are quick to remember, at least for me. I wonder how many people actually know their 9 digit zip.
- DannyBee 15y agoThis is fairly useful if you are trying to get mailing addresses, though you have to be careful about rural route areas and other crap. There are also plenty areas where people are required to use mailing addresses that do not match what the zipcode says. This is completely non-useful if you are trying to get residence addresses. Among other things: 1. There are plenty of places in the US where the zipcode serves an area many miles (IE 20+) away from the "city" associated with the zip code. 2. Postal boundaries do not match a lot of boundaries, and aren't updated as often. There are times when, for example, zip codes for towns in maryland were served from DC. So if you did reverse lookup on zip code, it would give you the wrong state and city. This still happens near boundaries of states. 3. ZIP+4 does not solve these issues with enough accuracy (It's only about 95% accurate). ZIP+9 is still wrong about the city in plenty of cases.
- mapster 15y agoAlso, zip codes may change service areas each year, and so would be necessary to use 3rd party zipcode database and do a spatial join to add city, county, state attributes to each zip code. then import this table to mysql as lookup table.
- orblivion 15y agoYou could always have the city state and country pop up as separate, pre-filled input boxes once the zip code is entered, so the user has a chance to correct it.
- drivebyacct2 15y agoOr even just pop up all the possible options. Still an immense and very much appreciated speedup.
- tobych 15y agoI worked for Avalara.com for a while: they help companies calculate sales tax based on location. I learned there that the five-digit ZIP code is certainly not enough. Some five-digit ZIP codes cross state boundaries, for one thing.