Search code examples
csvzippostal-code

How can I create an absurdly simple 'find nearest' zip code app without using maps?


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.


Solution

  • 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.