Zip code distance calculator for PHP
I haven't tried it yet, but this module from Micah Carrick (also link here) holds promise for calculating the distances between zip codes. It relies on a text file of Zip code lon/lats from CFDynamics. I'll post an update when I've tried this out. He includes code to build the MySQL tables from the text file.
Technorati Tags: zip code, postal code, php, programming, distance calculator


try this:
//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;
}
Posted by: Nitin | Jun 05, 2007 at 02:58 AM
nitn: try this
I did and it works nicely. Exactly what i was looking for. Thank you.
Posted by: mykl | Sep 15, 2007 at 01:02 PM
I would recommend http://www.zipcodesmapped.com/ for any US zip code map.
You can use this to find any US zip code maps. You can search by (City, State OR Zip). they have all the maps showing zip codes and major mile streets in all of the united states. The service is free. Search for five Digit Zip Code and find the Maps for all 50 states. A Free ZIP Code Finder which can do wonders for you.
Posted by: US zip code map | Jan 09, 2008 at 12:34 AM
I would recommend http://www.zipmap.info/ for any US zip code map.
You can use this to find any US zip code maps. You can search by (City,
State OR Zip). they have all the maps showing zip codes and major mile
streets in all of the united states. The service is free. Search for five
Digit Zip Code and find the Maps for all 50 states. A Free ZIP Code Finder
which can do wonders for you. Zip Map
Posted by: Zip Map | Feb 05, 2008 at 01:54 AM
Thanks
Posted by: DotCom | May 31, 2008 at 11:33 PM
You can get the free monthly updates ZIP code database from the following URL. The ZIP code list is good for validation purpose. Nothing wrong to give it a try as it is FREE.
http://www.zipcodeworld.com/zipcodefree.htm
Posted by: TIm | Oct 18, 2008 at 09:53 PM
Great code. Works great. Thanks!
Posted by: Alan | Jan 08, 2009 at 10:13 AM
Thanks for the code I will have to try it out. I did run across this FREE zip code DB.
http://databases.about.com/od/access/a/zipcodedatabase.htm
It lists the zips, state and long/lat.
It was updated during the 99 census, but should be accurate.
Posted by: Scott Johnson | Jan 17, 2009 at 08:28 AM
The script that Micah developed is great, and includes a very nice zip code database. I've used it in many projects and written a thorough step by step tutorial on implementing the script to allow users to search for things within range of a certain zip code. My little way of giving back. Check it out by clicking my name below
Posted by: Dave | Sep 10, 2009 at 05:59 PM