Skip to content

Instantly share code, notes, and snippets.

@ailinykh
Created June 11, 2013 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ailinykh/5756808 to your computer and use it in GitHub Desktop.
Save ailinykh/5756808 to your computer and use it in GitHub Desktop.
<?php
/**
* Distance
*
* @return distance betweeb two points in meters
*/
public function distance($lat1,$long1,$lat2,$long2)
{
$greatCircleRadius = 6372795;
$rLat1 = M_PI*$lat1/180;
$rLong1 = M_PI*$long1/180;
$rLat2 = M_PI*$lat2/180;
$rLong2 = M_PI*$long2/180;
return abs($greatCircleRadius*atan(
sqrt(
pow(cos($rLat2)*sin($rLong2-$rLong1),2)
+
pow(cos($rLat1)*sin($rLat2)
-
sin($rLat1)*cos($rLat2)*cos(abs($rLong2-$rLong1)),2)
)
/
(sin($rLat1)*sin($rLat2)+cos($rLat1)*cos($rLat2)*cos(abs($rLong2-$rLong1)))));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment