2

Specifically because of server restrictions for this project I cannot use anything like Google maps. I cannot use a database. I only have access to PHP 4.39 and FTP.

Zip/postal codes are in a CSV file.

The idea I had is the user types in their postal code, the script searches an array, matches the first two digits, plus or minus 2. This would not result in a perfect nearest match, but close enough.

Summary: accuracy is less important than simplicity for this project, I think.

Calydon
  • 251
  • 1
  • 9
  • Out of curiousity, what possible practical use could this have? – Wonko the Sane Apr 02 '12 at 19:03
  • @WonkotheSane my first guess would be something like searching neighborhoods for a direct mailing campaign. – iandouglas Apr 02 '12 at 20:32
  • Yes, but...in a city, "similar" zip codes may be around the corner, or may be miles away. Or, take somebody that lives near a border between states - the zip codes will probably be vastly different, but the proximity will not. Zip codes are generally alphabetic in configuration, not geographically. – Wonko the Sane Apr 02 '12 at 20:38
  • I can see that you are correct. I was really hoping there was a way to avoid having to use a list of coordinates. – Calydon Apr 02 '12 at 21:31

1 Answers1

2

You can download lists of zip codes which include latitude/longitude of the city centers for those zip files. It'd be more accurate to search based on a simple check of lat/long coordinates than to trust that two zip codes are geographically "close" simply because the numbers are within a small range.

For example, if you look at http://www.city-data.com/zipmaps/Los-Angeles-California.html you can see that a zip of 90048 and 90067 are geographically very close where 90058 is significantly farther away from 90048 compared to 90067.

Simply basing your search on zip codes will be nowhere nearly as accurate as you hope.

iandouglas
  • 4,146
  • 2
  • 33
  • 33
  • 2
    here's a neat article on how to find the zip codes within a lat/lng range. You could still use your plan of finding all zip codes within xxx digits of each other, find the lat/long box that fits them all, then use this approach to actually find other zips within a smaller radius from your center: http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/ – iandouglas Apr 02 '12 at 20:23