WGS84、GCJ02、BD911坐标相互转换

1、WGS84和BD911坐标相互转换使用百度地图API,代码如下:

    /**
     * WGS84坐标转换BD911坐标
     *  利用百度地图Api转换
     * @param longitude
     * @param latitude
     * @return
     */
    public static LatLng WGS84ToBd911(double longitude, double latitude){
        LatLng sourceLatLng=new LatLng(latitude,longitude);
        CoordinateConverter converter  = new CoordinateConverter();
        converter.from(CoordType.GPS);
        // sourceLatLng待转换坐标  
        converter.coord(sourceLatLng);  
        LatLng desLatLng = converter.convert();
        return desLatLng;
    }

2、JCG02转WGS84坐标系

    /**
     * gcj02坐标转换为WGS84坐标
     * @param gcj02Lon
     * @param gcj02Lat
     * @return
     */
    public static YNLocation gcj02ToWGS84(double gcj02Lon,double gcj02Lat){
        CoordsUtils coor = new CoordsUtils();
        YNLocation location = coor.gcj_decrypt(gcj02Lat,gcj02Lon);
        return location;
    }

JCG02坐标转换为GPS坐标工具类

/**
 * JCG02坐标转换为GPS坐标工具类
 *  参考网上资料
 * @date 2016年9月29日 下午2:59:25
 * @version V1.0
 */
public class CoordsUtils {

    private double PI = 3.14159265358979324;
    private double X_PI = 3.14159265358979324 * 3000.0 / 180.0;

    public YNLocation gcj_decrypt(double lat, double lon) {
        YNLocation d = delta(lat, lon);
        double latitude = lat-d.getLatitude();
        double longitude = lon-d.getLongitude();
        YNLocation location = new YNLocation();
        location.setLongitude(longitude);
        location.setLatitude(latitude);
        return location;
    }

    public YNLocation delta(double lat, double lon){
        double a = 6378245.0; //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
        double ee = 0.00669342162296594323; //  ee: 椭球的偏心率。
        double dLat = this.functionLat(lon - 105.0, lat - 35.0);
        double dLon = this.functionLon(lon - 105.0, lat - 35.0);
        double radLat = lat / 180.0 * this.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) * this.PI);
        dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
        YNLocation loc = new YNLocation();
        loc.setLongitude(dLon);
        loc.setLatitude(dLat);
        return loc;
    }

    private double functionLat (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 * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
        return ret;
    }

    private double functionLon (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 * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
        return ret;
    }

}

坐标实体类

/**
 * 位置信息
 */
public class YNLocation {

    /**
     * 经度
     */
    private double longitude;

    /**
     * 纬度
     */
    private double latitude;

    /**
     * 海拔
     */
    private double altitude;

    /**
     * 速度
     */
    private double speed;

    /**
     * 方向
     */
    private double direction;


    public YNLocation() {
        super();
    }
    public YNLocation(double longitude, double latitude) {
        super();
        this.longitude = longitude;
        this.latitude = latitude;
    }
    public double getLongitude() {
        return longitude;
    }
    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }
    public double getLatitude() {
        return latitude;
    }
    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }
    public double getAltitude() {
        return altitude;
    }
    public void setAltitude(double altitude) {
        this.altitude = altitude;
    }
    public double getSpeed() {
        return speed;
    }
    public void setSpeed(double speed) {
        this.speed = speed;
    }
    public double getDirection() {
        return direction;
    }
    public void setDirection(double direction) {
        this.direction = direction;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
WGS84坐标系转换GCJ02坐标系是一个常见的需求,在Java开发中可以使用提供的Java代码来实现。该代码可以在的博客中找到,可以参考该博客进行使用。 具体的转换过程如下: 1. 首先,你需要获取要转换WGS84坐标系的经度和纬度。 2. 然后,使用提供的Java代码,将WGS84坐标系的经度和纬度作为参数传入转换函数。 3. 转换函数会返回对应的GCJ02坐标系的经度和纬度。 4. 最后,你可以使用返回的GCJ02坐标系的经度和纬度进行后续的操作。 通过这个过程,你就可以将WGS84坐标系转换GCJ02坐标系了。请参考中的Java代码和说明来实现具体的转换过程。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [百度坐标(BD09)、国测局坐标(火星坐标GCJ02)、和WGS84坐标系之间的转换](https://download.csdn.net/download/junehappylove/11218182)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [java_adnroid_GPS坐标转换工具类的标准代码_百度坐标系 GCJ-02 WGS84 经纬度转换](https://download.csdn.net/download/qq_38334677/85377874)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱写程序

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值