PDA

View Full Version : Zip code proximity searches

Dan06
03-18-2009, 05:32 PM
I'd like to implement zip code proximity searches. What is required to do the search? Can anyone recommend any pre-made zip code proximity search scripts that I should look into?

Thanks.

mlseim
03-18-2009, 05:51 PM
I assumed you looked here first?

There are some free zipcode database listings you can download ...

And finally, Google Maps API:
http://www.mattcutts.com/blog/fun-with-zip-codes/

There are so many variations to zip code finding, nearest zip code, maps, etc.
You'll need to either be more specific, or give us an example of one you've seen.
But Google is your real friend for this one.

Fumigator
03-18-2009, 06:01 PM
It's a matter of getting the latitude and longitude of point A and point B (you'll want to access a database for that, there are free ones available) and then calculate distance from A to B.

//getDistance(\$lat1,\$log1,\$lat2,\$log2)

function getDistance(\$a1,\$b1,\$a2,\$b2)
{
\$r = 3963.1; //3963.1 statute miles; 3443.9 nautical miles; 6378 km
\$pi = 3.14159265358979323846;

//print "\$a1, \$b1, \$a2, \$b2, \$r, \$pi\n";
\$a1 = \$a1*(\$pi/180);
\$a2 = \$a2*(\$pi/180);
\$b1 = \$b1*(\$pi/180);
\$b2 = \$b2*(\$pi/180);

\$ret = (acos(cos(\$a1)*cos(\$b1)*cos(\$a2)*cos(\$b2) + cos(\$a1)*sin(\$b1)*cos(\$a2)*sin(\$b2) + sin(\$a1)*sin(\$a2)) * \$r) ;
//print "-- \$ret--\n";
return \$ret;
}

I got this snippet from http://www.idealog.us/2006/07/zip_code_distan.html

brazenskies
03-18-2009, 06:07 PM
google actually has the whole of the US geocoded.

I have a mysql script that does this nicely, even with it's limited spatial support!

I'll see if I can look it out

Dan06
03-19-2009, 02:31 AM
There are so many variations to zip code finding, nearest zip code, maps, etc.
You'll need to either be more specific, or give us an example of one you've seen.
But Google is your real friend for this one.

The type of zip code proximity search I'm interested in is the type that you see in car dealership sites - i.e. you enter your zip code, and then in a drop-down menu you choose your search radius: 5 or 10 or 15 miles etc. and depending on what you choose the dealerships within that range show up.

I've searched on google, but haven't found anything worthwhile yet.

@brazenskies:
If you can find that script you mentioned, I'd be very interested in looking at it.

Thanks.

mlseim
03-19-2009, 02:30 PM
http://www.hotscripts.com/category/php/scripts-programs/zip-code-locators/

Specifically the first few of them, even if you have to pay for them, they look promising.
In any event, it sounds like you'll need to customize anything you decide to use.