您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 计算 两个坐标之间的距离

2024/4/16 0:37:33发布31次查看
<?php define('earth_radius', 6378.137);//地球半径 define('pi', 3.1415926); /** * 计算两组经纬度坐标 之间的距离 * params :lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km); * return m or km */ function getdistance($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 * earth_radius; $s = round($s * 1000); if ($len_type > 1) { $s /= 1000; } return round($s, $decimal); } echo getdistance(39.908156,116.4767, 39.908452,116.450479, 1);//输出距离/米
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product