Function: Calculates the spherical distance between two points according to the latitude and longitude of pi and earth radius coefficients and coordinates of two points.
Get two point coordinate distance:
/** * Calculates the distance between two points of geographic coordinates * @param decimal $longitude 1 beginning Longitude * @param decimal $latitude 1 beginning latitude * @par Am Decimal $longitude 2 End Longitude * @param Decimal $latitude 2 End latitude * @param Int $unit Unit 1 : M 2: km * @param Int $decimal precision reserved decimal number * @return decimal * / functiongetdistance($longitude 1, $latitude 1, $ Longitude2, $latitude 2, $unit=2, $decimal=2){ $EARTH _radius=6370.996;//Earth radius coefficient$PI=3.1415926;$radLat 1=$latitude 1*$PI/180.0;$radLat 2=$latitude 2*$PI/180.0;$radLng 1=$longitude 1*$PI/180.0;$radLng 2=$longitude 2*$PI/180.0;$a=$radLat 1-$radLat 2;$b=$radLng 1-$radLng 2;$distance=2* ASIN (SQRT (Pow (sin ($a/2),2) + cos ($radLat 1) * COS ($radLat 2) * POW (sin ($b/2),2)));$distance=$distance*$EARTH _radius* +;if($unit==2){$distance=$distance/ +; }returnRound$distance,$decimal);}//Start coordinates$longitude 1=113.330405;$latitude 1=23.147255;//Terminal coordinates$longitude 2=113.314271;$latitude 2=23.1323;$distance= Getdistance ($longitude 1,$latitude 1,$longitude 2,$latitude 2,1);Echo$distance.' m ';//2342.38m$distance= Getdistance ($longitude 1,$latitude 1,$longitude 2,$latitude 2,2);Echo$distance.' km ';//2.34km?>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP two points of geographical coordinates of the distance, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.