: This article describes how to calculate the distance between two GPS points in PHP. For more information about PHP tutorials, see. The following is a function for PHP to calculate the distance between two GPS points:
PHP calculates the distance between two GPS points
Distance between two GPS coordinates calculated by Mysql
Javascript calculates the distance between two GPS points
# When lon is Longitude and lat is latitude, do not mistake function distance ($ lon1, $ lat1, $ lon2, $ lat2) {return (2 * ATAN2 (SQRT (SIN ($ lat1-$ lat2) * PI ()/180/2) * SIN ($ lat1-$ lat2) * PI () /180/2) + COS ($ lat2 * PI ()/180) * COS ($ lat1 * PI ()/180) * SIN ($ lon1-$ lon2) * PI ()/180/2) * SIN ($ lon1-$ lon2) * PI ()/180/2), SQRT (1-SIN ($ lat1-$ lat2) * PI ()/180/2) * SIN ($ lat1-$ lat2) * PI ()/180/2) + COS ($ lat2 * PI ()/180) * COS ($ lat1 * PI ()/180) * SIN ($ lon1-$ lon2) * PI ()/180/2) * SIN ($ lon1-$ lon2) * PI ()/180/2) * 6378140 ;}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# When lon is Longitude and lat is latitude, do not make a mistake.
Functiondistance ($ lon1, $ lat1, $ lon2, $ lat2 ){
Return (2 * ATAN2 (SQRT (SIN ($ lat1-$ lat2) * PI ()/180/2)
* SIN ($ lat1-$ lat2) * PI ()/180/2) +
COS ($ lat2 * PI ()/180) * COS ($ lat1 * PI ()/180)
* SIN ($ lon1-$ lon2) * PI ()/180/2)
* SIN ($ lon1-$ lon2) * PI ()/180/2 )),
SQRT (1-SIN ($ lat1-$ lat2) * PI ()/180/2)
* SIN ($ lat1-$ lat2) * PI ()/180/2)
+ COS ($ lat2 * PI ()/180) * COS ($ lat1 * PI ()/180)
* SIN ($ lon1-$ lon2) * PI ()/180/2)
* SIN ($ lon1-$ lon2) * PI ()/180/2) * 6378140;
}
|
Call method:
Echo distance (39.91917, 116.3896, 39.91726, 116.3940 );
|
1
|
Echodistance (39.91917, 116.3896, 39.91726, 116.3940 );
|
The preceding section describes the distance between two GPS points in PHP computing, including the following content. I hope my friends who are interested in the PHP Tutorial will be helpful.