This article describes how php calculates the distance between two coordinates (longitude, latitude). It involves the use of php-related mathematical functions and is very useful. For more information, see
This article describes how php calculates the distance between two coordinates (longitude, latitude). It involves the use of php-related mathematical functions and is very useful. For more information, see
This article describes how php calculates the distance between two coordinates (longitude and latitude. Share it with you for your reference. The details are as follows:
Here, we use php to calculate the distance between two coordinates (longitude, latitude). The returned result is meter or kilometer.
Function distance ($ lat1, $ lng1, $ lat2, $ lng2, $ miles = true) {$ pi80 = M_PI/180; $ lat1 * = $ pi80; $ lng1 * = $ pi80; $ lat2 x = $ pi80; $ lng2 * = $ pi80; $ r = 6372.797; // mean radius of Earth in km $ dlat = $ lat2-$ lat1; $ dlng = $ lng2-$ lng1; $ a = sin ($ dlat/2) * sin ($ dlat/2) + cos ($ lat1) * cos ($ lat2) * 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 will help you with php programming.
,