PHP calculates the distance between two coordinates (longitude, latitude), coordinates longitude
This example describes how PHP calculates the distance between two coordinates (longitude, latitude). Share to everyone for your reference. Specific as follows:
Here we use PHP to calculate the distance between two coordinates (longitude, latitude) and return the result to meters or kilometers.
function distance ($lat 1, $lng 1, $lat 2, $lng 2, $miles = True) {$pi = m_pi/180; $lat 1 *= $pi; $lng 1 *= $pi; $lat 2 *= $PI 80; $LNG 2 *= $PI 80; $r = 6372.797; Mean radius of Earth in miles $dlat = $lat 2-$lat 1; $DLNG = $lng 2-$LNG 1; $a = sin ($dlat/2) *sin ($dlat/2) +cos ($lat 1) *cos ($lat 2) *sin ($DLNG/2) *sin ($DLNG/2); $c = 2 * atan2 (sqrt ($a), sqrt (1-$a)); $km = $r * $c; Return ($miles? ($KM * 0.621371192): $km);}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/985268.html www.bkjia.com true http://www.bkjia.com/PHPjc/985268.html techarticle PHP calculates the distance between two coordinates (longitude, latitude), coordinate longitude This example describes the method by which PHP calculates the distance between two coordinates (longitude, latitude). To share with you ...