PackageCom.hjb.util;ImportJava.util.HashMap;ImportJava.util.Map; Public classBaidumapstoautonavimaputils {Static DoublePI = 3.14159265358979324; Static DoubleA = 6378245.0; Static DoubleEE = 0.00669342162296594323; Static DoubleX_PI = 3.14159265358979324 * 3000.0/180.0; //World Geodetic System ==> Mars Geodetic System Public StaticMap<string, String> transform (DoubleWglat,DoubleWglon) {Map<string, string> resultmap =NewHashmap<string, string>(); DoubleMglat = 0; DoubleMglon = 0; if(Outofchina (Wglat, Wglon)) {Mglat=Wglat; Mglon=Wglon; Resultmap.put ("Mglat", String.valueof (Mglat)); Resultmap.put ("Mglon", String.valueof (Mglon)); returnResultmap; } DoubleDlat = Transformlat (wgLon-105.0, wgLat-35.0); DoubleDlon = Transformlon (wgLon-105.0, wgLat-35.0); DoubleRadlat = wglat/180.0 *Pi; DoubleMagic =Math.sin (Radlat); Magic= 1-ee * Magic *Magic; DoubleSqrtmagic =math.sqrt (Magic); Dlat= (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) *pi); Dlon= (Dlon * 180.0)/(A/sqrtmagic * MATH.COS (Radlat) *pi); Mglat= Wglat +Dlat; Mglon= Wglon +Dlon; Resultmap.put ("Mglat", String.valueof (Mglat)); Resultmap.put ("Mglon", String.valueof (Mglon)); returnResultmap; } Static BooleanOutofchina (DoubleLatDoubleLon) { if(Lon < 72.004 | | Lon > 137.8347) return true; if(Lat < 0.8293 | | | lat > 55.8271) return true; return false; } Static DoubleTransformlat (DoubleXDoubley) {DoubleRET = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 *math.sqrt (Math.Abs (x)); RET+ = (20.0 * Math.sin (6.0 * x * pi) + 20.0 * Math.sin (2.0 * x * pi)) * 2.0/3.0; RET+ = (20.0 * Math.sin (y * pi) + 40.0 * Math.sin (y/3.0 * pi)) * 2.0/3.0; RET+ = (160.0 * Math.sin (y/12.0 * pi) + * * Math.sin (Y * pi/30.0)) * 2.0/3.0; returnret; } Static DoubleTransformlon (DoubleXDoubley) {DoubleRET = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 *math.sqrt (Math.Abs (x)); RET+ = (20.0 * Math.sin (6.0 * x * pi) + 20.0 * Math.sin (2.0 * x * pi)) * 2.0/3.0; RET+ = (20.0 * Math.sin (x * pi) + 40.0 * Math.sin (x/3.0 * pi)) * 2.0/3.0; RET+ = (150.0 * Math.sin (x/12.0 * pi) + 300.0 * Math.sin (x/30.0 * pi)) * 2.0/3.0; returnret; } /*** GCJ-02 (Mars coordinates) and BD-09 (Baidu coordinates) * Bd_encrypt convert GCJ-02 coordinates to BD-09 coordinates, bd_decrypt vice versa. * @paramBd_lat *@paramBd_lon *@paramGg_lat *@paramGg_lon*/ Public StaticMap<string, String> Bd_encrypt (DoubleGg_lat,DoubleGg_lon) {Map<string, string> resultmap =NewHashmap<string,string>(); DoubleBd_lat = 0; DoubleBd_lon = 0; Doublex = Gg_lon, y =Gg_lat; Doublez = MATH.SQRT (x * x + y * y) + 0.00002 * Math.sin (Y *x_pi); Doubletheta = math.atan2 (y, x) + 0.000003 * MATH.COS (x *x_pi); Bd_lon= Z * Math.Cos (theta) + 0.0065; Bd_lat= Z * Math.sin (theta) + 0.006; Resultmap.put ("Mglat", String.valueof (Bd_lat)); Resultmap.put ("Mglon", String.valueof (Bd_lon)); returnResultmap; } /*** GCJ-02 (Mars coordinates) and BD-09 (Baidu coordinates) * Bd_encrypt convert GCJ-02 coordinates to BD-09 coordinates, bd_decrypt vice versa. * @paramBd_lat *@paramBd_lon *@paramGg_lat *@paramGg_lon*/ Public StaticMap<string, String> Bd_decrypt (DoubleBd_lat,DoubleBd_lon) {Map<string, string> resultmap =NewHashmap<string,string>(); DoubleGg_lat = 0; DoubleGg_lon = 0; Doublex = bd_lon-0.0065, y = bd_lat-0.006; Doublez = MATH.SQRT (x * x + y * y)-0.00002 * Math.sin (Y *x_pi); Doubletheta = math.atan2 (y, x)-0.000003 * MATH.COS (x *x_pi); Gg_lon= Z *Math.Cos (theta); Gg_lat= Z *Math.sin (theta); Resultmap.put ("Mglat", String.valueof (Gg_lat)); Resultmap.put ("Mglon", String.valueof (Gg_lon)); returnResultmap; }}
Conversion algorithm of Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09)