PHP计算百度地图两个GPS坐标之间的距离代码
发布时间:2016-10-13 编辑:jiaochengji.com
教程集为您提供PHP计算百度地图两个GPS坐标之间的距离代码等资源,欢迎您收藏本站,我们将为您提供最新的PHP计算百度地图两个GPS坐标之间的距离代码资源
应用百度地图时,我们如何用php计算两个GPS经纬度坐标之间的距离呢?现在我们把函数代码分享给你。
以下是我分享的用PHP计算两个GPS经纬度坐标之间的距离的代码,有需要的朋友可以直接拿去用。
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4467')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4467>/*** 计算两个坐标之间的距离(米)
* @param float $fP1Lat 起点(纬度)
* @param float $fP1Lon 起点(经度)
* @param float $fP2Lat 终点(纬度)
* @param float $fP2Lon 终点(经度)
* @return int
*/
function distanceBetween($fP1Lat, $fP1Lon, $fP2Lat, $fP2Lon){
$fEARTH_RADIUS = 6378137;
//角度换算成弧度
$fRadLon1 = deg2rad($fP1Lon);
$fRadLon2 = deg2rad($fP2Lon);
$fRadLat1 = deg2rad($fP1Lat);
$fRadLat2 = deg2rad($fP2Lat);
//计算经纬度的差值
$fD1 = abs($fRadLat1 - $fRadLat2);
$fD2 = abs($fRadLon1 - $fRadLon2);
//距离计算
$fP = pow(sin($fD1/2), 2)
cos($fRadLat1) * cos($fRadLat2) * pow(sin($fD2/2), 2);
return intval($fEARTH_RADIUS * 2 * asin(sqrt($fP)) 0.5);
}
/**
* 百度坐标系转换成标准GPS坐系
* @param float $lnglat 坐标(如:106.426, 29.553404)
* @return string 转换后的标准GPS值:
*/
function BD09LLtoWGS84($fLng, $fLat){ // 经度,纬度
$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.','.$GPS_y;//经度,纬度
}else
return $lnglat;
}</td></tr></table>
您可能感兴趣的文章:
PHP计算百度地图两个GPS坐标之间的距离代码
php计算两个坐标(经度,纬度)之间距离的方法
PHP计算地球上两点之间的距离(示例详解)
php计算两个经纬度地点之间距离的方法分享
Jquery图形报表插件 jqplot简介及参数详解
jqPlot Option配置对象详解
jqPlot 基于jquery的画图插件
老师不会教的【DIV间距设置】技巧
python怎么制作游戏脚本
jquery jqPlot API 中文使用教程(非常强大的图表工具)
[关闭]