Conversion algorithm of Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09)

Source: Internet
Author: User
Tags cos sin

 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.