/**
* 圆周率
* @param $lat1 自己的经纬度22.xx
* @param $lng1 自己的经纬度108.xx
* @param $lat2 目标的经纬度22.xx
* @param $lng2 目标的经纬度108.xx
* @param int $len_type
* @param int $decimal
*/
public static function getRatio($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)
{
$radLat1 = $lat1 * PI ()/ 180.0;
$radLat2 = $lat2 * PI() / 180.0;
$a = $radLat1 - $radLat2;
$b = ($lng1 * PI() / 180.0) - ($lng2 * PI() / 180.0);
$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));
$s = $s * 6378.137;
$s = round($s * 1000);
if ($len_type == 1)
{
$s /= 1000;
}
return round($s, $decimal);
}
|