Standard coordinate system longitude and latitude to Baidu Mars coordinate system latitude and longitude degree

Source: Internet
Author: User
Tags abs cos sin

         standard coordinate system latitude and longitude of the Baidu Mars coordinate system, the code is as follows:

Package com.qwrt.fire.sensor.util;
 /** * Created by Jack on 2018/4/27.
    * The Mars coordinate system (GCJ-02) and the Baidu coordinate system (BD-09) Mutual turn/public class Gpsutil {public static double pi = 3.1415926535897932384626;
    public static Double x_pi = 3.14159265358979324 * 3000.0/180.0;
    public static Double A = 6378245.0;

    public static Double ee = 0.00669342162296594323; public 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; public 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; public static double[] transform (double lat, double lon) {if (Outofchina (lat, lon)) {return NE
        W Double[]{lat,lon};
        Double Dlat = Transformlat (lon-105.0, lat-35.0);
        Double Dlon = Transformlon (lon-105.0, lat-35.0);
        Double Radlat = lat/180.0 * PI;
        Double magic = Math.sin (Radlat);
        Magic = 1-ee * Magic * MAGIC;
        Double sqrtmagic = math.sqrt (Magic);
        Dlat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) * pi);
        Dlon = (Dlon * 180.0)/(A/sqrtmagic * MATH.COS (Radlat) * pi);
        Double Mglat = lat + Dlat;
     Double Mglon = lon + Dlon;   return new Double[]{mglat,mglon};
            public static Boolean Outofchina (double lat, double lon) {if (Lon < 72.004 | | lon > 137.8347)
        return true;
        if (Lat < 0.8293 | | | lat > 55.8271) return true;
    return false; /** * To Mars coordinate system (GCJ-02) World geodetic System ==> Mars geodetic System * * @param lat * @p Aram Lon * @return/public static double[] gps84_to_gcj02 (double lat, double lon) {if (Outofchina (Lat, lon))
        {return new Double[]{lat,lon};
        Double Dlat = Transformlat (lon-105.0, lat-35.0);
        Double Dlon = Transformlon (lon-105.0, lat-35.0);
        Double Radlat = lat/180.0 * PI;
        Double magic = Math.sin (Radlat);
        Magic = 1-ee * Magic * MAGIC;
        Double sqrtmagic = math.sqrt (Magic);
        Dlat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) * pi); Dlon = (Dlon * 180.0)/(A/sqrtmAgic * MATH.COS (Radlat) * pi);
        Double Mglat = lat + Dlat;
        Double Mglon = lon + Dlon;
    return new Double[]{mglat, Mglon}; /** * * Mars coordinate system (GCJ-02) to * * @param lon * @param lat * @return */public static double[] Gcj02_
        TO_GPS84 (double lat, double lon) {double[] GPs = transform (lat, lon);
        Double lontitude = lon * 2-GPS[1];
        Double latitude = lat * 2-gps[0];
    return new Double[]{latitude, lontitude};
     The conversion algorithm of the/** * Mars coordinate system (GCJ-02) and the Baidu coordinate system (BD-09) converts GCJ-02 coordinates into BD-09 coordinates * * @param lat * @param lon
        */public static double[] gcj02_to_bd09 (double lat, double lon) {Double x = lon, y = lat;
        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 Templon = z * Math.Cos (theta) + 0.0065;
        Double Templat = z * Math.sin (theta) + 0.006; Double[] GPS = {Templat,templon};
    return GPS; /** * * Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09) conversion algorithm * Convert BD-09 coordinates to GCJ-02 coordinates * * @param * Bd_lat * @param bd_lo n * @return */public static double[] bd09_to_gcj02 (double lat, double lon) {Double x = lon-0.0065, y
        = 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 Templon = z * Math.Cos (theta);
        Double Templat = z * Math.sin (theta);
        Double[] GPs = {Templat,templon};
    return GPS; /** convert gps84 to BD09 * @param lat * @param lon * @return * * public static double[] Gps84_to_bd09 (Double lat,double lon)
        {double[] gcj02 = gps84_to_gcj02 (Lat,lon);
        double[] bd09 = gcj02_to_bd09 (gcj02[0],gcj02[1));
    return bd09; public static double[] BD09_TO_GPS84 (double lat,double lon) {double[] gcj02 = bd09_to_gcj02 (lat, LON);
        double[] gps84 = GCJ02_TO_GPS84 (Gcj02[0], gcj02[1]);
        Six-bit gps84[0] = retain6 (gps84[0]) after the decimal point is reserved;
        GPS84[1] = retain6 (gps84[1]);
    return gps84; /** retains six decimal @param num * @return/private static double retain6 (double num) {String
        result = String. Format ("%.6f", num);
    return double.valueof (Result);
 }
}

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.