|
@@ -9,6 +9,36 @@ namespace algorithm;
|
|
|
class Geometry
|
|
|
{
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 火星坐标Gcj02 转 WGS84
|
|
|
+ *
|
|
|
+ * @param double $lat 纬度
|
|
|
+ * @param double $lng 经度
|
|
|
+ */
|
|
|
+ public static function gcj02ToWgs84($lat, $lng)
|
|
|
+ {
|
|
|
+
|
|
|
+ $pi = 3.14159265358979324;
|
|
|
+ $a = 6378245.0;
|
|
|
+ $ee = 0.00669342162296594323;
|
|
|
+
|
|
|
+ $dlat = self::wgsTOgcjTransformLat($lng - 105.0, $lat - 35.0);
|
|
|
+ $dlng = self::wgsTOgcjTransformLon($lng - 105.0, $lat - 35.0);
|
|
|
+ $radlat = $lat / 180.0 * $pi;
|
|
|
+ $magic = sin($radlat);
|
|
|
+ $magic = 1 - $ee * $magic * $magic;
|
|
|
+ $sqrtmagic = sqrt($magic);
|
|
|
+ $dlat = ($dlat * 180.0) / (($a * (1 - $ee)) / ($magic * $sqrtmagic) * $pi);
|
|
|
+ $dlng = ($dlng * 180.0) / ($a / $sqrtmagic * cos($radlat) * $pi);
|
|
|
+ $mglat = $lat + $dlat;
|
|
|
+ $mglng = $lng + $dlng;
|
|
|
+ return [
|
|
|
+ 'lng' => $lng * 2 - $mglng,
|
|
|
+ 'lat' => $lat * 2 - $mglat,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 火星坐标Gcj02 转 百度地图坐标BD09
|
|
|
* 腾讯地图用的也是GCJ02坐标
|