Not much to say, your own code on the line, you can directly to use.
/** * Calculates the distance between two coordinates (m) * @param float $fP 1Lat starting point (latitude) * @param float $fP 1Lon Start (longitude) * @param float $fP 2Lat end point (latitude) * @param fl Oat $fP 2Lon Endpoint (longitude) * @return int */function distancebetween ($fP 1Lat, $fP 1Lon, $fP 2Lat, $fP 2Lon) {$fEARTH _radius = 6378137;/ /angle converted to radians $fradlon1 = Deg2rad ($fP 1Lon), $fRadLon 2 = Deg2rad ($fP 2Lon), $fRadLat 1 = Deg2rad ($fP 1Lat), $fRadLat 2 = Deg2rad ($ Fp2lat);//Calculate the difference between longitude and latitude $fd1 = ABS ($fRadLat 1-$fRadLat 2), $fD 2 = ABS ($fRadLon 1-$fRadLon 2);//Distance calculation $fp = Pow (sin ($fD), 2) + C OS ($fRadLat 1) * cos ($fRadLat 2) * POW (sin ($fD 2/2), 2), return intval ($fEARTH _radius * 2 * ASIN (SQRT ($fP)) + 0.5);} /** * Baidu coordinate system converted to standard GPS sitting system * @param float $lnglat coordinates (e.g. 106.426, 29.553404) * @return The standard GPS value after string conversion: */function BD09LLTOWGS8 4 ($fLng, $fLat) {//longitude, latitude $lnglat = explode (', ', $lnglat); list ($x, $y) = $lnglat; $Baidu _server = "http://api.map.baidu.com /ag/coord/convert?from=0&to=4&x={$x}&y={$y} "; $result = @file_get_contents ($Baidu _server); $json = Json_ Decode ($result); if ($json->error = = 0) {$BX = basE64_decode ($json->x); $by = Base64_decode ($json->y); $GPS _x = 2 * $x-$bx; $GPS _y = 2 * $y-$by; return $GPS _x. ', '. $GP s_y;//longitude, Latitude}elsereturn $lnglat;}
Calculates the distance between two GPs latitude and longitude coordinates PHP