{"id":1920,"date":"2020-12-18T16:39:27","date_gmt":"2020-12-18T08:39:27","guid":{"rendered":"https:\/\/www.xiaobo.li\/?p=1920"},"modified":"2020-12-18T16:39:27","modified_gmt":"2020-12-18T08:39:27","slug":"%e5%9c%b0%e5%9b%be%e5%9d%90%e6%a0%87%e7%b3%bb%e7%9a%84%e8%bd%ac%e6%8d%a2wgs-84%e3%80%81gcj-02%e3%80%81bd-09","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/1920","title":{"rendered":"\u5730\u56fe\u5750\u6807\u7cfb\u7684\u8f6c\u6362(WGS-84\u3001GCJ-02\u3001BD-09)"},"content":{"rendered":"<p>C#\u5730\u56fe\u5750\u6807\u7cfb\u7684\u8f6c\u6362(WGS-84\u3001GCJ-02\u3001BD-09)<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cs\">public class GPSChange\r\n    {\r\n        private const double pi = 3.14159265358979324;\r\n        private const double x_pi = 3.14159265358979324 * 3000.0 \/ 180.0;\r\n\r\n        \/\/\u514b\u62c9\u7d22\u5929\u65af\u57fa\u692d\u7403\u4f53\u53c2\u6570\u503c\r\n        private const double a = 6378245.0;\r\n        \/\/\u7b2c\u4e00\u504f\u5fc3\u7387\r\n        private const double ee = 0.00669342162296594323;\r\n\r\n\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/ GCJ-02\u8f6c\u6362BD-09\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=\"gg_lat\"&gt;\u7eac\u5ea6&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"gg_lon\"&gt;\u7ecf\u5ea6&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public static GPSPoint GCJ02_to_BD09(double gg_lat, double gg_lon)\r\n        {\r\n            GPSPoint point = new GPSPoint();\r\n            double x = gg_lon, y = gg_lat;\r\n            double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi);\r\n            double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi);\r\n            double bd_lon = z * Math.Cos(theta) + 0.0065;\r\n            double bd_lat = z * Math.Sin(theta) + 0.006;\r\n            point.SetLat(bd_lat);\r\n            point.SetLng(bd_lon);\r\n            return point;\r\n        }\r\n\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/ BD-09\u8f6c\u6362GCJ-02\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=\"bd_lat\"&gt;\u7eac\u5ea6&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"bd_lon\"&gt;\u7ecf\u5ea6&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public static GPSPoint BD09_to_GCJ02(double bd_lat, double bd_lon)\r\n        {\r\n            GPSPoint point = new GPSPoint();\r\n            double x = bd_lon - 0.0065, y = bd_lat - 0.006;\r\n            double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi);\r\n            double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * x_pi);\r\n            double gg_lon = z * Math.Cos(theta);\r\n            double gg_lat = z * Math.Sin(theta);\r\n            point.SetLat(gg_lat);\r\n            point.SetLng(gg_lon);\r\n            return point;\r\n        }\r\n\r\n\r\n\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/ WGS-84\u8f6c\u6362GCJ-02\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=\"wgLat\"&gt;\u7eac\u5ea6&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"wgLon\"&gt;\u7ecf\u5ea6&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public static GPSPoint WGS84_to_GCJ02(double wgLat, double wgLon)\r\n        {\r\n            GPSPoint point = new GPSPoint();\r\n            if (OutOfChina(wgLat, wgLon))\r\n            {\r\n                point.SetLat(wgLat);\r\n                point.SetLng(wgLon);\r\n                return point;\r\n            }\r\n            double dLat = TransformLat(wgLon - 105.0, wgLat - 35.0);\r\n            double dLon = TransformLon(wgLon - 105.0, wgLat - 35.0);\r\n            double radLat = wgLat \/ 180.0 * pi;\r\n            double magic = Math.Sin(radLat);\r\n            magic = 1 - ee * magic * magic;\r\n            double sqrtMagic = Math.Sqrt(magic);\r\n            dLat = (dLat * 180.0) \/ ((a * (1 - ee)) \/ (magic * sqrtMagic) * pi);\r\n            dLon = (dLon * 180.0) \/ (a \/ sqrtMagic * Math.Cos(radLat) * pi);\r\n            double lat = wgLat + dLat;\r\n            double lon = wgLon + dLon;\r\n            point.SetLat(lat);\r\n            point.SetLng(lon);\r\n            return point;\r\n        }\r\n\r\n\r\n        public static void Transform(double wgLat, double wgLon, double[] latlng)\r\n        {\r\n            if (OutOfChina(wgLat, wgLon))\r\n            {\r\n                latlng[0] = wgLat;\r\n                latlng[1] = wgLon;\r\n                return;\r\n            }\r\n            double dLat = TransformLat(wgLon - 105.0, wgLat - 35.0);\r\n            double dLon = TransformLon(wgLon - 105.0, wgLat - 35.0);\r\n            double radLat = wgLat \/ 180.0 * pi;\r\n            double magic = Math.Sin(radLat);\r\n            magic = 1 - ee * magic * magic;\r\n            double sqrtMagic = Math.Sqrt(magic);\r\n            dLat = (dLat * 180.0) \/ ((a * (1 - ee)) \/ (magic * sqrtMagic) * pi);\r\n            dLon = (dLon * 180.0) \/ (a \/ sqrtMagic * Math.Cos(radLat) * pi);\r\n            latlng[0] = wgLat + dLat;\r\n            latlng[1] = wgLon + dLon;\r\n        }\r\n\r\n        private static bool OutOfChina(double lat, double lon)\r\n        {\r\n            if (lon &lt; 72.004 || lon &gt; 137.8347)\r\n                return true;\r\n            if (lat &lt; 0.8293 || lat &gt; 55.8271)\r\n                return true;\r\n            return false;\r\n        }\r\n\r\n        private static double TransformLat(double x, double y)\r\n        {\r\n            double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x));\r\n            ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 \/ 3.0;\r\n            ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y \/ 3.0 * pi)) * 2.0 \/ 3.0;\r\n            ret += (160.0 * Math.Sin(y \/ 12.0 * pi) + 320 * Math.Sin(y * pi \/ 30.0)) * 2.0 \/ 3.0;\r\n            return ret;\r\n        }\r\n\r\n        private static double TransformLon(double x, double y)\r\n        {\r\n            double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x));\r\n            ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 \/ 3.0;\r\n            ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x \/ 3.0 * pi)) * 2.0 \/ 3.0;\r\n            ret += (150.0 * Math.Sin(x \/ 12.0 * pi) + 300.0 * Math.Sin(x \/ 30.0 * pi)) * 2.0 \/ 3.0;\r\n            return ret;\r\n        }\r\n\r\n    }<\/code><\/pre>\n<p>.<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cs\">public class GPSPoint\r\n    {\r\n        private double lat;\/\/ \u7eac\u5ea6\r\n        private double lng;\/\/ \u7ecf\u5ea6\r\n\r\n        public GPSPoint()\r\n        {\r\n        }\r\n\r\n        public GPSPoint(double lng, double lat)\r\n        {\r\n            this.lng = lng;\r\n            this.lat = lat;\r\n        }\r\n\r\n        \r\n        public double GetLat()\r\n        {\r\n            return lat;\r\n        }\r\n        public void SetLat(double lat)\r\n        {\r\n            this.lat = lat;\r\n        }\r\n        public double GetLng()\r\n        {\r\n            return lng;\r\n        }\r\n        public void SetLng(double lng)\r\n        {\r\n            this.lng = lng;\r\n        }\r\n        \r\n\r\n    }<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>.<\/p>\n<p>Java\u5b9e\u73b0<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"java\">package com.map.util;\r\n\r\npublic class GPSUtil {  \r\n    public static double pi = 3.1415926535897932384626;  \r\n    public static double x_pi = 3.14159265358979324 * 3000.0 \/ 180.0;  \r\n    public static double a = 6378245.0;  \r\n    public static double ee = 0.00669342162296594323;  \r\n  \r\n    public static double transformLat(double x, double y) {  \r\n        double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y  \r\n                + 0.2 * Math.sqrt(Math.abs(x));  \r\n        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 \/ 3.0;  \r\n        ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y \/ 3.0 * pi)) * 2.0 \/ 3.0;  \r\n        ret += (160.0 * Math.sin(y \/ 12.0 * pi) + 320 * Math.sin(y * pi \/ 30.0)) * 2.0 \/ 3.0;  \r\n        return ret;  \r\n    }  \r\n  \r\n    public static double transformLon(double x, double y) {  \r\n        double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1  \r\n                * Math.sqrt(Math.abs(x));  \r\n        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 \/ 3.0;  \r\n        ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x \/ 3.0 * pi)) * 2.0 \/ 3.0;  \r\n        ret += (150.0 * Math.sin(x \/ 12.0 * pi) + 300.0 * Math.sin(x \/ 30.0  \r\n                * pi)) * 2.0 \/ 3.0;  \r\n        return ret;  \r\n    }  \r\n    public static double[] transform(double lat, double lon) {  \r\n        if (outOfChina(lat, lon)) {  \r\n            return new double[]{lat,lon};  \r\n        }  \r\n        double dLat = transformLat(lon - 105.0, lat - 35.0);  \r\n        double dLon = transformLon(lon - 105.0, lat - 35.0);  \r\n        double radLat = lat \/ 180.0 * pi;  \r\n        double magic = Math.sin(radLat);  \r\n        magic = 1 - ee * magic * magic;  \r\n        double sqrtMagic = Math.sqrt(magic);  \r\n        dLat = (dLat * 180.0) \/ ((a * (1 - ee)) \/ (magic * sqrtMagic) * pi);  \r\n        dLon = (dLon * 180.0) \/ (a \/ sqrtMagic * Math.cos(radLat) * pi);  \r\n        double mgLat = lat + dLat;  \r\n        double mgLon = lon + dLon;  \r\n        return new double[]{mgLat,mgLon};  \r\n    }  \r\n    public static boolean outOfChina(double lat, double lon) {  \r\n        if (lon &lt; 72.004 || lon &gt; 137.8347)  \r\n            return true;  \r\n        if (lat &lt; 0.8293 || lat &gt; 55.8271)  \r\n            return true;  \r\n        return false;  \r\n    }  \r\n    \/** \r\n     * 84 to \u706b\u661f\u5750\u6807\u7cfb (GCJ-02) World Geodetic System ==&gt; Mars Geodetic System \r\n     * \r\n     * @param lat \r\n     * @param lon \r\n     * @return \r\n     *\/  \r\n    public static double[] gps84_To_Gcj02(double lat, double lon) {  \r\n        if (outOfChina(lat, lon)) {  \r\n            return new double[]{lat,lon};  \r\n        }  \r\n        double dLat = transformLat(lon - 105.0, lat - 35.0);  \r\n        double dLon = transformLon(lon - 105.0, lat - 35.0);  \r\n        double radLat = lat \/ 180.0 * pi;  \r\n        double magic = Math.sin(radLat);  \r\n        magic = 1 - ee * magic * magic;  \r\n        double sqrtMagic = Math.sqrt(magic);  \r\n        dLat = (dLat * 180.0) \/ ((a * (1 - ee)) \/ (magic * sqrtMagic) * pi);  \r\n        dLon = (dLon * 180.0) \/ (a \/ sqrtMagic * Math.cos(radLat) * pi);  \r\n        double mgLat = lat + dLat;  \r\n        double mgLon = lon + dLon;  \r\n        return new double[]{mgLat, mgLon};  \r\n    }  \r\n  \r\n    \/** \r\n     * * \u706b\u661f\u5750\u6807\u7cfb (GCJ-02) to 84 * * @param lon * @param lat * @return \r\n     * *\/  \r\n    public static double[] gcj02_To_Gps84(double lat, double lon) {  \r\n        double[] gps = transform(lat, lon);  \r\n        double lontitude = lon * 2 - gps[1];  \r\n        double latitude = lat * 2 - gps[0];  \r\n        return new double[]{latitude, lontitude};  \r\n    }  \r\n    \/** \r\n     * \u706b\u661f\u5750\u6807\u7cfb (GCJ-02) \u4e0e\u767e\u5ea6\u5750\u6807\u7cfb (BD-09) \u7684\u8f6c\u6362\u7b97\u6cd5 \u5c06 GCJ-02 \u5750\u6807\u8f6c\u6362\u6210 BD-09 \u5750\u6807 \r\n     * \r\n     * @param lat \r\n     * @param lon \r\n     *\/  \r\n    public static double[] gcj02_To_Bd09(double lat, double lon) {  \r\n        double x = lon, y = lat;  \r\n        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);  \r\n        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);  \r\n        double tempLon = z * Math.cos(theta) + 0.0065;  \r\n        double tempLat = z * Math.sin(theta) + 0.006;  \r\n        double[] gps = {tempLat,tempLon};  \r\n        return gps;  \r\n    }  \r\n  \r\n    \/** \r\n     * * \u706b\u661f\u5750\u6807\u7cfb (GCJ-02) \u4e0e\u767e\u5ea6\u5750\u6807\u7cfb (BD-09) \u7684\u8f6c\u6362\u7b97\u6cd5 * * \u5c06 BD-09 \u5750\u6807\u8f6c\u6362\u6210GCJ-02 \u5750\u6807 * * @param \r\n     * bd_lat * @param bd_lon * @return \r\n     *\/  \r\n    public static double[] bd09_To_Gcj02(double lat, double lon) {  \r\n        double x = lon - 0.0065, y = lat - 0.006;  \r\n        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);  \r\n        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);  \r\n        double tempLon = z * Math.cos(theta);  \r\n        double tempLat = z * Math.sin(theta);  \r\n        double[] gps = {tempLat,tempLon};  \r\n        return gps;  \r\n    }  \r\n  \r\n    \/**\u5c06gps84\u8f6c\u4e3abd09 \r\n     * @param lat \r\n     * @param lon \r\n     * @return \r\n     *\/  \r\n    public static double[] gps84_To_bd09(double lat,double lon){  \r\n        double[] gcj02 = gps84_To_Gcj02(lat,lon);  \r\n        double[] bd09 = gcj02_To_Bd09(gcj02[0],gcj02[1]);  \r\n        return bd09;  \r\n    }  \r\n    public static double[] bd09_To_gps84(double lat,double lon){  \r\n        double[] gcj02 = bd09_To_Gcj02(lat, lon);  \r\n        double[] gps84 = gcj02_To_Gps84(gcj02[0], gcj02[1]);  \r\n        \/\/\u4fdd\u7559\u5c0f\u6570\u70b9\u540e\u516d\u4f4d  \r\n        gps84[0] = retain6(gps84[0]);  \r\n        gps84[1] = retain6(gps84[1]);  \r\n        return gps84;  \r\n    }  \r\n  \r\n    \/**\u4fdd\u7559\u5c0f\u6570\u70b9\u540e\u516d\u4f4d \r\n     * @param num \r\n     * @return \r\n     *\/  \r\n    private static double retain6(double num){  \r\n        String result = String .format(\"%.6f\", num);  \r\n        return Double.valueOf(result);  \r\n    }  \r\n  \r\n} <\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>.<\/p>\n<p>js\u5b9e\u73b0<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"javascript\">var GPS = {\r\n    PI : 3.14159265358979324,\r\n    x_pi : 3.14159265358979324 * 3000.0 \/ 180.0,\r\n    delta : function (lat, lon) {\r\n        \/\/ Krasovsky 1940\r\n        \/\/\r\n        \/\/ a = 6378245.0, 1\/f = 298.3\r\n        \/\/ b = a * (1 - f)\r\n        \/\/ ee = (a^2 - b^2) \/ a^2;\r\n        var a = 6378245.0; \/\/  a: \u536b\u661f\u692d\u7403\u5750\u6807\u6295\u5f71\u5230\u5e73\u9762\u5730\u56fe\u5750\u6807\u7cfb\u7684\u6295\u5f71\u56e0\u5b50\u3002\r\n        var ee = 0.00669342162296594323; \/\/  ee: \u692d\u7403\u7684\u504f\u5fc3\u7387\u3002\r\n        var dLat = this.transformLat(lon - 105.0, lat - 35.0);\r\n        var dLon = this.transformLon(lon - 105.0, lat - 35.0);\r\n        var radLat = lat \/ 180.0 * this.PI;\r\n        var magic = Math.sin(radLat);\r\n        magic = 1 - ee * magic * magic;\r\n        var sqrtMagic = Math.sqrt(magic);\r\n        dLat = (dLat * 180.0) \/ ((a * (1 - ee)) \/ (magic * sqrtMagic) * this.PI);\r\n        dLon = (dLon * 180.0) \/ (a \/ sqrtMagic * Math.cos(radLat) * this.PI);\r\n        return {'lat': dLat, 'lon': dLon};\r\n    },\r\n\r\n    \/\/WGS-84 to GCJ-02\r\n    gcj_encrypt : function (wgsLat, wgsLon) {\r\n        if (this.outOfChina(wgsLat, wgsLon))\r\n            return {'lat': wgsLat, 'lon': wgsLon};\r\n\r\n        var d = this.delta(wgsLat, wgsLon);\r\n        return {'lat' : wgsLat + d.lat,'lon' : wgsLon + d.lon};\r\n    },\r\n    \/\/GCJ-02 to WGS-84\r\n    gcj_decrypt : function (gcjLat, gcjLon) {\r\n        if (this.outOfChina(gcjLat, gcjLon))\r\n            return {'lat': gcjLat, 'lon': gcjLon};\r\n\r\n        var d = this.delta(gcjLat, gcjLon);\r\n        return {'lat': gcjLat - d.lat, 'lon': gcjLon - d.lon};\r\n    },\r\n    \/\/GCJ-02 to WGS-84 exactly\r\n    gcj_decrypt_exact : function (gcjLat, gcjLon) {\r\n        var initDelta = 0.01;\r\n        var threshold = 0.000000001;\r\n        var dLat = initDelta, dLon = initDelta;\r\n        var mLat = gcjLat - dLat, mLon = gcjLon - dLon;\r\n        var pLat = gcjLat + dLat, pLon = gcjLon + dLon;\r\n        var wgsLat, wgsLon, i = 0;\r\n        while (1) {\r\n            wgsLat = (mLat + pLat) \/ 2;\r\n            wgsLon = (mLon + pLon) \/ 2;\r\n            var tmp = this.gcj_encrypt(wgsLat, wgsLon)\r\n            dLat = tmp.lat - gcjLat;\r\n            dLon = tmp.lon - gcjLon;\r\n            if ((Math.abs(dLat) &lt; threshold) &amp;&amp; (Math.abs(dLon) &lt; threshold))\r\n                break;\r\n\r\n            if (dLat &gt; 0) pLat = wgsLat; else mLat = wgsLat;\r\n            if (dLon &gt; 0) pLon = wgsLon; else mLon = wgsLon;\r\n\r\n            if (++i &gt; 10000) break;\r\n        }\r\n        \/\/console.log(i);\r\n        return {'lat': wgsLat, 'lon': wgsLon};\r\n    },\r\n    \/\/GCJ-02 to BD-09\r\n    bd_encrypt : function (gcjLat, gcjLon) {\r\n        var x = gcjLon, y = gcjLat;\r\n        var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi);\r\n        var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi);\r\n        bdLon = z * Math.cos(theta) + 0.0065;\r\n        bdLat = z * Math.sin(theta) + 0.006;\r\n        return {'lat' : bdLat,'lon' : bdLon};\r\n    },\r\n    \/\/BD-09 to GCJ-02\r\n    bd_decrypt : function (bdLat, bdLon) {\r\n        var x = bdLon - 0.0065, y = bdLat - 0.006;\r\n        var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi);\r\n        var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi);\r\n        var gcjLon = z * Math.cos(theta);\r\n        var gcjLat = z * Math.sin(theta);\r\n        return {'lat' : gcjLat, 'lon' : gcjLon};\r\n    },\r\n    \/\/WGS-84 to Web mercator\r\n    \/\/mercatorLat -&gt; y mercatorLon -&gt; x\r\n    mercator_encrypt : function(wgsLat, wgsLon) {\r\n        var x = wgsLon * 20037508.34 \/ 180.;\r\n        var y = Math.log(Math.tan((90. + wgsLat) * this.PI \/ 360.)) \/ (this.PI \/ 180.);\r\n        y = y * 20037508.34 \/ 180.;\r\n        return {'lat' : y, 'lon' : x};\r\n        \/*\r\n         if ((Math.abs(wgsLon) &gt; 180 || Math.abs(wgsLat) &gt; 90))\r\n         return null;\r\n         var x = 6378137.0 * wgsLon * 0.017453292519943295;\r\n         var a = wgsLat * 0.017453292519943295;\r\n         var y = 3189068.5 * Math.log((1.0 + Math.sin(a)) \/ (1.0 - Math.sin(a)));\r\n         return {'lat' : y, 'lon' : x};\r\n         \/\/*\/\r\n    },\r\n    \/\/ Web mercator to WGS-84\r\n    \/\/ mercatorLat -&gt; y mercatorLon -&gt; x\r\n    mercator_decrypt : function(mercatorLat, mercatorLon) {\r\n        var x = mercatorLon \/ 20037508.34 * 180.;\r\n        var y = mercatorLat \/ 20037508.34 * 180.;\r\n        y = 180 \/ this.PI * (2 * Math.atan(Math.exp(y * this.PI \/ 180.)) - this.PI \/ 2);\r\n        return {'lat' : y, 'lon' : x};\r\n        \/*\r\n         if (Math.abs(mercatorLon) &lt; 180 &amp;&amp; Math.abs(mercatorLat) &lt; 90)\r\n         return null;\r\n         if ((Math.abs(mercatorLon) &gt; 20037508.3427892) || (Math.abs(mercatorLat) &gt; 20037508.3427892))\r\n         return null;\r\n         var a = mercatorLon \/ 6378137.0 * 57.295779513082323;\r\n         var x = a - (Math.floor(((a + 180.0) \/ 360.0)) * 360.0);\r\n         var y = (1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * mercatorLat) \/ 6378137.0)))) * 57.295779513082323;\r\n         return {'lat' : y, 'lon' : x};\r\n         \/\/*\/\r\n    },\r\n    \/\/ two point's distance\r\n    distance : function (latA, lonA, latB, lonB) {\r\n        var earthR = 6371000.;\r\n        var x = Math.cos(latA * this.PI \/ 180.) * Math.cos(latB * this.PI \/ 180.) * Math.cos((lonA - lonB) * this.PI \/ 180);\r\n        var y = Math.sin(latA * this.PI \/ 180.) * Math.sin(latB * this.PI \/ 180.);\r\n        var s = x + y;\r\n        if (s &gt; 1) s = 1;\r\n        if (s &lt; -1) s = -1;\r\n        var alpha = Math.acos(s);\r\n        var distance = alpha * earthR;\r\n        return distance;\r\n    },\r\n    outOfChina : function (lat, lon) {\r\n        if (lon &lt; 72.004 || lon &gt; 137.8347)\r\n            return true;\r\n        if (lat &lt; 0.8293 || lat &gt; 55.8271)\r\n            return true;\r\n        return false;\r\n    },\r\n    transformLat : function (x, y) {\r\n        var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));\r\n        ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 \/ 3.0;\r\n        ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y \/ 3.0 * this.PI)) * 2.0 \/ 3.0;\r\n        ret += (160.0 * Math.sin(y \/ 12.0 * this.PI) + 320 * Math.sin(y * this.PI \/ 30.0)) * 2.0 \/ 3.0;\r\n        return ret;\r\n    },\r\n    transformLon : function (x, y) {\r\n        var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));\r\n        ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 \/ 3.0;\r\n        ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x \/ 3.0 * this.PI)) * 2.0 \/ 3.0;\r\n        ret += (150.0 * Math.sin(x \/ 12.0 * this.PI) + 300.0 * Math.sin(x \/ 30.0 * this.PI)) * 2.0 \/ 3.0;\r\n        return ret;\r\n    }\r\n};<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C#\u5730\u56fe\u5750\u6807\u7cfb\u7684\u8f6c\u6362(WGS-84\u3001GCJ-02\u3001BD-09) public c &hellip; <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/1920\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[318],"tags":[],"class_list":["post-1920","post","type-post","status-publish","format-standard","hentry","category-gps"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/1920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=1920"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/1920\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=1920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=1920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=1920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}