map换算

来源:互联网 发布:淘宝网如何盈利模式 编辑:程序博客网 时间:2024/05/21 13:15
/** 
* 百度地图BD09坐标---->中国正常GCJ02坐标 
* 腾讯地图用的也是GCJ02坐标 
* @param double $lat 纬度 
* @param double $lng 经度 
* @return array(); 
*/  
function Convert_BD09_To_GCJ02($data){
$x_pi = 3.14159265358979324 * 3000.0 / 180.0;
foreach($data as $k => $v){
$x = $v['longitude'] - 0.0065;  
$y = $v['latitude'] - 0.006;  
$z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);  
$theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);  
$lng = $z * cos($theta);  
$lat = $z * sin($theta); 
$data[$k]['longitude']=$lng;
$data[$k]['latitude']=$lat;
return $data;exit;
//return array('lng'=>$lng,'lat'=>$lat);
}

}

/** 
* 中国正常GCJ02坐标---->百度地图BD09坐标 
* 腾讯地图用的也是GCJ02坐标 
* @param double $lat 纬度 
* @param double $lng 经度 
*/  
function Convert_GCJ02_To_BD09($lat,$lng){  
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;  
        $x = $lng;  
        $y = $lat;  
        $z =sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);  
        $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);  
        $lng = $z * cos($theta) + 0.0065;  
        $lat = $z * sin($theta) + 0.006;  
        return array('lng'=>$lng,'lat'=>$lat);  

/**
 * 计算坐标点范围,可以做搜索用户
 * @param float $lat
 * @param float $lng
 * @param float $raidus 范围
 * @return array
 */
function GetRange($lng,$lat,$raidus){
$PI = 3.1415926535898;


//计算纬度
$degree = (24901 * 1609) / 360.0;
$dpmLat = 1 / $degree; 
$radiusLat = $dpmLat * $raidus;
$minLat = $lat - $radiusLat; //得到最小纬度
$maxLat = $lat + $radiusLat; //得到最大纬度   
//计算经度
$mpdLng = $degree * cos($lat * ($PI / 180));
$dpmLng = 1 / $mpdLng;
$radiusLng = $dpmLng * $raidus;
$minLng = $lng - $radiusLng;  //得到最小经度
$maxLng = $lng + $radiusLng;  //得到最大经度
//范围
$range = array(
'minLat' => $minLat,
'maxLat' => $maxLat,
'minLng' => $minLng,
'maxLng' => $maxLng
);
return $range;
}


/**
 * 获取2点之间的距离
 * @param float $lat1
 * @param float $lng1
 * @param float $lat2
 * @param float $lng2
 * @return float
 */
//function GetDistance($lng1, $lat1, $lng2, $lat2){ 
// $EARTH_RADIUS = 6378.137;//地球弧度
// $PI = 3.1415926535898;
//
// $radLat1 = $lat1 * ($PI / 180);
// $radLat2 = $lat2 * ($PI / 180);
// 
// $a = $radLat1 - $radLat2; 
// $b = ($lng1 * ($PI / 180)) - ($lng2 * ($PI / 180)); 
 //
// $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,1) / 10; 
// return $s; 
//}


function getDistance($lat1, $lng1, $lat2, $lng2)
 {
     $earthRadius = 6367000; //approximate radius of earth in meters


     /*
       Convert these degrees to radians
       to work with the formula
     */


     $lat1 = ($lat1 * pi() ) / 180;
     $lng1 = ($lng1 * pi() ) / 180;


     $lat2 = ($lat2 * pi() ) / 180;
     $lng2 = ($lng2 * pi() ) / 180;


     /*
       Using the
       Haversine formula


       http://en.wikipedia.org/wiki/Haversine_formula


       calculate the distance
     */


     $calcLongitude = $lng2 - $lng1;
     $calcLatitude = $lat2 - $lat1;
     $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);  $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
     $calculatedDistance = $earthRadius * $stepTwo;


     return round($calculatedDistance);
 }

/**
 * 返回毫秒级时间戳
 * @access public
 * @param int $length 位数(默认毫秒是3位)
 * @param string $type 返回值类型(int整形,string字符串型)
 * @return string/int 如果为int、可能会科学计数法展示
 */
function get_micro_time($length=3,$type='string'){
$temp = explode(" ", microtime());
// echo $temp[0],'<br>';//毫秒小数位 0.854327001445485876
// echo $temp[1],'<br>';//秒,和时间戳一样 1537465906


if( $type == 'string' ){
$re = round( $temp[0]*pow(10,$length) );
settype($re,$type);
settype($temp[1],$type);
return $temp[1].$re;
}else{
$re = bcadd($temp[0], $temp[1], $length);//二者相加、保留 $length 位小数
return $re*pow(10,$length);//6位竟然返回1.4454856885957E+15
}
}




原创粉丝点击