1 /**2 * Created by Wandergis on 2015/7/8.3 * Provides the conversion between Baidu coordinates (BD09), National geodetic coordinates (MARS coordinates, GCJ02), and WGS84 coordinate system4 */5 //Define some constants6 varX_PI = 3.14159265358979324 * 3000.0/180.0;7 varPI = 3.1415926535897932384626;8 varA = 6378245.0;9 varEE = 0.00669342162296594323;Ten /** One * Conversion of the Baidu coordinate system (BD-09) to the Mars coordinate system (GCJ-02) A * That is, Baidu turned to Google, the German - * @param Bd_lon - * @param bd_lat the * @returns {*[]} - */ - functionbd09togcj02 (Bd_lon, Bd_lat) { - varX_PI = 3.14159265358979324 * 3000.0/180.0; + varx = bd_lon-0.0065; - vary = bd_lat-0.006; + varz = MATH.SQRT (x * x + y * y)-0.00002 * Math.sin (Y *x_pi); A vartheta = math.atan2 (y, x)-0.000003 * MATH.COS (x *x_pi); at varGG_LNG = Z *Math.Cos (theta); - varGg_lat = Z *Math.sin (theta); - return[GG_LNG, Gg_lat] - } - /** - * Conversion of Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09) in * That is, Google, high-German switch Baidu - * @param LNG to * @param lat + * @returns {*[]} - */ the functiongcj02tobd09 (LNG, LAT) { * varz = MATH.SQRT (LNG * LNG + lat * lat) + 0.00002 * Math.sin (LAT *x_pi); $ vartheta = math.atan2 (lat, LNG) + 0.000003 * MATH.COS (LNG *x_pi);Panax Notoginseng varBD_LNG = Z * Math.Cos (theta) + 0.0065; - varBd_lat = Z * Math.sin (theta) + 0.006; the return[BD_LNG, Bd_lat] + } A /** the * WGS84 Turn GCj02 + * @param LNG - * @param lat $ * @returns {*[]} $ */ - functionwgs84togcj02 (LNG, LAT) { - if(Out_of_china (LNG, LAT)) { the return[LNG, LAT] - }Wuyi Else { the varDlat = Transformlat (lng-105.0, lat-35.0); - varDLNG = TRANSFORMLNG (lng-105.0, lat-35.0); Wu varRadlat = lat/180.0 *PI; - varMagic =Math.sin (Radlat); AboutMagic = 1-ee * Magic *Magic; $ varSqrtmagic =math.sqrt (Magic); -Dlat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) *PI); -DLNG = (DLNG * 180.0)/(A/sqrtmagic * MATH.COS (Radlat) *PI); - varMglat = Lat +Dlat; A varMGLNG = LNG +dlng; + return[MGLNG, Mglat] the } - } $ /** the * GCJ02 converted to WGS84 the * @param LNG the * @param lat the * @returns {*[]} - */ in functiongcj02towgs84 (LNG, LAT) { the if(Out_of_china (LNG, LAT)) { the return[LNG, LAT] About } the Else { the varDlat = Transformlat (lng-105.0, lat-35.0); the varDLNG = TRANSFORMLNG (lng-105.0, lat-35.0); + varRadlat = lat/180.0 *PI; - varMagic =Math.sin (Radlat); theMagic = 1-ee * Magic *Magic;Bayi varSqrtmagic =math.sqrt (Magic); theDlat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) *PI); theDLNG = (DLNG * 180.0)/(A/sqrtmagic * MATH.COS (Radlat) *PI); -Mglat = Lat +Dlat; -MGLNG = LNG +dlng; the return[LNG * 2-mglng, LAT * 2-Mglat] the } the } the functionTransformlat (LNG, LAT) { - varRET = -100.0 + 2.0 * LNG + 3.0 * LAT + 0.2 * lat * lat + 0.1 * LNG * LAT + 0.2 *math.sqrt (Math.Abs (LNG)); theRET + = (20.0 * Math.sin (6.0 * LNG * pi) + 20.0 * Math.sin (2.0 * LNG * pi)) * 2.0/3.0; theRET + = (20.0 * Math.sin (LAT * PI) + 40.0 * Math.sin (lat/3.0 * pi)) * 2.0/3.0; theRET + = (160.0 * Math.sin (lat/12.0 * PI) + * * Math.sin (LAT * pi/30.0)) * 2.0/3.0;94 returnret the } the functiontransformlng (LNG, LAT) { the varRET = 300.0 + LNG + 2.0 * LAT + 0.1 * LNG * LNG + 0.1 * LNG * LAT + 0.1 *math.sqrt (Math.Abs (LNG));98RET + = (20.0 * Math.sin (6.0 * LNG * pi) + 20.0 * Math.sin (2.0 * LNG * pi)) * 2.0/3.0; AboutRET + = (20.0 * Math.sin (LNG * pi) + 40.0 * Math.sin (lng/3.0 * pi)) * 2.0/3.0; -RET + = (150.0 * Math.sin (lng/12.0 * pi) + 300.0 * Math.sin (lng/30.0 * pi)) * 2.0/3.0;101 returnret102 }103 /**104 * To determine whether in the domestic, not in the country do not offset the * @param LNG106 * @param lat107 * @returns {Boolean}108 */109 functionOut_of_china (LNG, LAT) { the return(LNG < 72.004 | | LNG > 137.8347) | | (Lat < 0.8293 | | | lat > 55.8271) | |false);111}
Reprint Please specify source: web that dissected thing? Conversion between the coordinate coordinate system of Baidu (JS version code)
"Turn" the conversion between Baidu coordinate coordinate system (JS version code)