Jerry has asked for the wisdom of the Perl Monks concerning the following question:
-Jerry
http://www.digilliance.net
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Zipcode search engine
by Jazz (Curate) on Sep 10, 2001 at 04:36 UTC | |
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 | [reply] [d/l] |
|
Re: Zipcode search engine
by shotgunefx (Parson) on Sep 10, 2001 at 02:53 UTC | |
I used it for a project before but I don't have the name of the company handy. I'll look for it and post it if I find the company. UPDATE The zipcode db I was speaking of is available at zipinfo.com. They provide several ways of calculating distance with various degrees of precision. -Lee "To be civilized is to deny one's nature." | [reply] |
|
Re: Zipcode search engine
by tachyon (Chancellor) on Sep 10, 2001 at 03:42 UTC | |
At this point, I'm merely numerically comparing the user's zipcode to each one in the database and determining whether to return or discard each record. Is there a better way to do this? Probably. This sounds like you are using a flat file 'data base' and simply iterating from the beginning of this to the end. For a small file this works fine but breaks down when you get bigger and or demand on access to this file becomes high. On way to arrange this in a proper database would be to have two tables:
You do the lookup on the Zip table (really basic SQL) to get the Dist ID(s) for that area (Pipe delimited here). You then grab all those Distributors from the Dist table. Presumbaly the Distributor ID table should already exist? So you just need to generate a Zip table that cross references the Zip code to the Dist ID. You could do this manually using a map or automate it using the zip code geographic position data mentioned elsewhere. You would probable need to get geographic co-ordinates for you distributors but this is pretty easy. You can get the longs and lats for any US city from many of the online mapping services free. See jcwren monk map page (on the stats pages) for one such link. You could implement this using DBI and DBD::CSV making it easy to move to a real database in the future. tachyon s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print | [reply] [d/l] |
by mandog (Curate) on Sep 10, 2001 at 06:24 UTC | |
If you call call the UPSPS National Customer Support Center at (800) 238-3150 you can talk to the them about ordering zip/latitude/longitude data The documentation for this data is available as a pdf on the usps site. It seems like most people find a vendor to give them this data.The USPS FAQ talks about it a bit. I'm guessing that the 'ol a**2 + b**2 =c**2 would be how you would compute the shortest distance between two arbitrary zip codes. No doubt the monk map uses nicer code...
Of course you have to (pre?) compute the distance between the user's zip code and many of the other zip codes in your database... | [reply] [d/l] |
by ralphie (Friar) on Sep 10, 2001 at 04:14 UTC | |
zip distributor | [reply] |
|
Re: Zipcode search engine
by George_Sherston (Vicar) on Sep 10, 2001 at 01:15 UTC | |
§ George Sherston | [reply] |