« Jungle Disk and Amazon S3 - Backup for Your Life | Main | Reading Other People's Email »

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: , , , ,

Comments

Nitin

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;
}

mykl

nitn: try this

I did and it works nicely. Exactly what i was looking for. Thank you.

US zip code map

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.

Zip Map

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

DotCom

Thanks

TIm

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

Alan

Great code. Works great. Thanks!

Scott Johnson

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.

Dave

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

Post a comment

Comments are moderated, and will not appear on this weblog until the author has approved them.

If you have a TypeKey or TypePad account, please Sign In.