Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Zipcode search engineby Jazz (Curate) |
on Sep 10, 2001 at 04:36 UTC ( [id://111364]=note: print w/replies, xml ) | Need Help?? |
Update: Code updated to do reverse lookups. Now can do either city/state to zips and zip to city/state.
True, in theory, postal codes fairly closely relate to proximal cities, but where to start and stop the range? For example, New York City, NY, a comparatively small city (in square miles) has 162 zip codes ranging from 10001 -> 10292. Meaning, within that range there are 129 unused zip code numbers. Fayetteville, AR, much larger in area (950 sq miles) than NYC (309 sq miles), has only 4 zip codes 72701 - 72704. After NYC's 10292 zip, the next used zip is 10301, Staten Island. A short ferry ride away (or a bridge, if you're in Brooklyn), but a different island altogether and not the most convenient "closest store" from Manhattan. So the question is what range should be associated with what region? Since the answer is difficult (if not impossible) to guess, let's defer to the USPS. The following code will take a city and state and return all other zip codes for that city. It may not offer as broad a range as you'd like (nearby cities?), but at least you know that you're really pointing them to a location that's "nearby". It also will let you check to see if a zip code that you're "guessing" is actually in the same area by returning the associated city/state (hint -- offer the cities and let the user select which is closest and/or most convenient to them).
The above should be pretty self-explanatory, but if you have any questions, just holler. Any optimizations or suggestions (both desired) would be most welcome :) Jasmine
In Section
Seekers of Perl Wisdom
|
|