Google Maps Baidu map GPS latitude and longitude shift conversion (JAVA)

Source: Internet
Author: User
Tags cos sin

not much to say, direct code, Java Edition

Mainly Google Maps, Baidu map, GPS latitude and longitude shift conversion

GCJ-02 conversion Bd-09,google Map latitude and longitude to Baidu map latitude and longitude
BD-09 conversion GCJ-02, Baidu to Google
WGS-84 to GCJ-02 conversion (i.e. GPS bias)

/** * used to construct coordinate points in the map * @author LW * **/public class Point { Private double lat;//latitude private double lng;//longitude public point () {}public point (double LNG, double lat) {this.lng = Lng;this . lat = lat;} @Overridepublic boolean equals (Object obj) {if (obj instanceof point) {point bmappoint = (point) Obj;return (bmappoint.get LNG () = = LNG && Bmappoint.getlat () = = LAT)? True:false;} else {return false;}} Public double Getlat () {return lat;} public void Setlat (double lat) {This.lat = lat;} Public double getlng () {return LNG;} public void setlng (double lng) {this.lng = LNG;} @Overridepublic String toString () {return "point [lat=" + Lat + ", lng=" + LNG + "]";}} 
/** * Map coordinates conversion GOOGLE,BAIDU,GPS * @author LW * @Time April 16, 2015 18:19:16 * * */public class Coordinateconversion {private St  Atic Final Double x_pi = 3.14159265358979324 * 3000.0/180.0;private static final double pi = 3.14159265358979324;private Static final Double A = 6378245.0;private static final Double ee = 0.00669342162296594323;/** * Gg_lat latitude * Gg_lon Longitude * G CJ-02 Conversion BD-09 * Google Maps latitude and longitude to Baidu map latitude and longitude * */public static point Google_bd_encrypt (double Gg_lat, double gg_lon) {point Point=ne W Point ();d ouble x = gg_lon, y = gg_lat;double z = math.sqrt (x * x + y * y) + 0.00002 * Math.sin (y * x_pi);d ouble theta = Math.atan2 (y, x) + 0.000003 * MATH.COS (x * x_pi); Double Bd_lon = z * Math.Cos (theta) + 0.0065;double Bd_lat = z * Math.sin (theta) + 0.006;point.setlat (Bd_lat);p oint.setlng (Bd_lon); return point;} /** * Wglat Latitude * Wglon Longitude * BD-09 conversion GCJ-02 * Baidu to Google * */public static point Bd_google_encrypt (double Bd_lat, double bd_l    On) {point point=new point (); Double x = bd_lon-0.0065, y = bd_lat-0.006;      Double z = math.sqrt (x * x + y * y)-0.00002 * Math.sin (y * x_pi);      Double Theta =math.atan2 (y, x)-0.000003 * MATH.COS (x * x_pi);      Double Gg_lon = z * Math.Cos (theta);      Double Gg_lat = z * Math.sin (theta);    Point.setlat (Gg_lat);    POINT.SETLNG (Gg_lon); return point;} /** * Wglat Latitude * Wglon longitude * WGS-84 to GCJ-02 conversion (i.e. GPS bias) * */public static point wgs_gcj_encrypts (double Wglat, double WG Lon) {point point=new Point (), if (Outofchina (Wglat, Wglon)) {Point.setlat (Wglat);p oint.setlng (Wglon); Double Dlat = Transformlat (wgLon-105.0, wgLat-35.0);d ouble Dlon = Transformlon (wgLon-105.0, wgLat-35.0);d ouble rad Lat = wglat/180.0 * Pi;double Magic = Math.sin (Radlat); magic = 1-ee * Magic * magic;double sqrtmagic = math.sqrt (Magic );d lat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) * pi);d lon = (Dlon * 180.0)/(A/sqrtmagic * Math.Cos (RA Dlat) * pi);d ouble lat = wglat + dlat;double lon = Wglon + dlon;point.setlat (LAT);p oint.setlng (lON), return point; public static void transform (double Wglat, double Wglon, double[] latlng) {if (Outofchina (Wglat, Wglon)) {Latlng[0] = Wgla T;LATLNG[1] = Wglon;return;} Double Dlat = Transformlat (wgLon-105.0, wgLat-35.0);d ouble Dlon = Transformlon (wgLon-105.0, wgLat-35.0);d ouble rad Lat = wglat/180.0 * Pi;double Magic = Math.sin (Radlat); magic = 1-ee * Magic * magic;double sqrtmagic = math.sqrt (Magic );d lat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) * pi);d lon = (Dlon * 180.0)/(A/sqrtmagic * Math.Cos (RA Dlat) * pi); latlng[0] = Wglat + dlat;latlng[1] = Wglon + Dlon;} private static Boolean Outofchina (double lat, double lon) {if (Lon < 72.004 | | lon > 137.8347) return true;if (Lat &l T 0.8293 | | Lat > 55.8271) return True;return false;} private static Double Transformlat (double x, double y) {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)), 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;return ret;}  private static Double Transformlon (double x, double y) {double ret = 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;return ret;}}

Statement : The algorithm is not from himself, to collate the verification through


Google Maps Baidu map GPS latitude and longitude shift conversion (JAVA)

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.