依据经纬度计算距离的公式、百度坐标转换成GPS坐标(PHP版)

WBOY
Release: 2016-06-13 10:31:35
Original
1593 people have browsed it

根据经纬度计算距离的公式、百度坐标转换成GPS坐标(PHP版)

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.','.$GPS_y;//经度,纬度 } else return $lnglat;}/**********************************************/function fn_rad($d){ return $d * pi() / 180.0;}// 2点间算法function P2PDistance($latlng1,$latlng2){ // 纬度1,经度1 ~ 纬度2,经度2 $latlng1 = explode(',',$latlng1); $latlng2 = explode(',',$latlng2); list($lat1,$lng1) = $latlng1; list($lat2,$lng2) = $latlng2; $EARTH_RADIUS = 6378.137; $radLat1 = fn_rad($lat1); $radLat2 = fn_rad($lat2); $a = $radLat1 - $radLat2; $b = fn_rad($lng1) - fn_rad($lng2); $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 * 10000) / 10000; return number_format($s,2);}echo '百度坐标: ',$lnglat,'

','转换后GPS坐标: ',FromBaiduToGpsXY($lnglat),'

';echo '转换前距离: ',P2PDistance('31.224286666667,121.420675','31.224665,121.437518'),'
';echo '转换后距离: ',P2PDistance('31.224286666667,121.420675','31.220157068379,121.42647022694');?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!