Created
May 9, 2011 13:55
-
-
Save joshhartman/962554 to your computer and use it in GitHub Desktop.
Calculate the Distance Between Two Geo Coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Calculate distance between 2 sets of longitude/latitude coordinates | |
// Takes two sets of coordinates in decimal longitude and latitude format and returns the distance in miles. | |
// php, distance, coordinates, longitude, latitude | |
// Oelwein, IA | |
$lat1 = 42.6733171; | |
$lon1 = -91.9135036; | |
// Independence, IA | |
$lat2 = 42.4685978; | |
$lon2 = -91.8893386; | |
$distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); | |
echo 'The distance from '.$lat1.', '.$lon2.' to '.$lat2.', '.$lon2.' is '.$distance.' mi.'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment