标签:
1 <?php 2 //1、GCJ-02,国测局02年发布的坐标体系。又称“火星坐标”。谷歌,腾讯,高德都在用这个坐标体系。 3 //2、BD-09,百度坐标系 4 //GCJ-02转换BD-09 5 function GCJTobaidu($lat, $lng){ 6 $v = M_PI * 3000.0 / 180.0; 7 $x = $lng; 8 $y = $lat; 9 10 $z = sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $v); 11 $t = atan2($y, $x) + 0.000003 * cos($x * $v); 12 13 return array( 14 ‘lat‘ => $z * sin($t) + 0.006, 15 ‘lng‘ => $z * cos($t) + 0.0065 16 ); 17 } 18 19 //使用方法 20 $lat = 40.09974; 21 $lng = 116.24847; 22 $coordinate = GCJTobaidu($lat, $lng); 23 var_dump($coordinate); 24 25 //BD-09转换GCJ-02 26 function baiduToGCJ($lat, $lng){ 27 $v = M_PI * 3000.0 / 180.0; 28 $x = $lng - 0.0065; 29 $y = $lat - 0.006; 30 31 $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $v); 32 $t = atan2($y, $x) - 0.000003 * cos($x * $v); 33 34 return array( 35 ‘lat‘ => $z * sin($t), 36 ‘lng‘ => $z * cos($t) 37 ); 38 } 39 40 //使用方法 41 $lat = 40.10599; 42 $lng = 116.25489; 43 $coordinate = baiduToGCJ($lat, $lng); 44 var_dump($coordinate);
标签:
原文地址:http://www.cnblogs.com/xingmeng/p/4318329.html