Calculates the distance between two latitude and longitude by using PHP.
/*
* Calculate the distance between two latitude and longitude (in meters)
* */
<strong>public function </strong>getdistanceaction () { $lng 1=117.27; Longitude 1 $lat 1=31.86; Latitude 1 $lng 2=120.19; Longitude 2 $lat 2=30.26; Latitude 2 $EARTH _radius = 6378137; Earth radius $RAD = Pi ()/180.0; $radLat 1 = $lat 1 * $RAD; $radLat 2 = $lat 2 * $RAD; $a = $radLat 1-$radLat 2; Two points latitude difference $b = ($lng 1-$lng 2) * $RAD; Two-point longitude difference $s = 2 * ASIN (sqrt (Pow (sin ($a/2), 2) + cos ($radLat 1) * cos ($radLat 2) * POW (sin ($b/2), 2))); $s = $s * $EARTH _radius; $s = round ($s * 10000)/10000; Print_r ($s); Correct answer: 330518.674}
This article describes the use of PHP to calculate the distance between two latitude and longitude, more relevant content please follow the PHP Chinese web.