Forum OpenACS Q&A: Re: zip code proximity search

Collapse
Posted by Chris Davies on
having looked at this for a consultant locator service, I think you are pretty much destinated for triangulation from the reference data.  I have resolved to write this after converting my database using 5.0's categories api.

Since the tiger files are imported (with some errors I might add), basically you have the zip code and the lat/long of the center point of the zip code.

From that, with a little vector math, you can take the lat/long of your subsets, and come up with a vector which can then be converted to miles or some other scalar.

Since the US is pretty small compared to the world, you could probably use some average to fix the difference in lat/long distances as you get closer to the pole.  The closer to the pole, the shorter the distance between each degree of longitude.

I don't think you could say with any great certainty the exact distance, but, you could do the vector math and determine the listings in ascending scalar length.

-- or so the theory goes.

Another way to cheat would be to take the original zip code, get the FIPS county code, and then pull any listing with a similar FIPS county code making the assumption that people won't generally go out of their county to find whatever service.  Much simpler to implement -- but people living near Washington DC can easily drive 20 minutes and reach 5 counties, 2 states and the district.

I haven't had the time to write an api to use the reference data, and haven't seen anything that does this already.  If I finish before you, I'll publish the api.

The data that is used for the Tiger files is actually a one-off project that the Census Bureau did and if I recall, is not something they have supported since 1999.