百度坐标 火星坐标 相互转换

这篇文章提供了两个Java方法,分别用于将百度坐标(bd09II)转换为火星坐标(GCJ02),以及反过来,从火星坐标到百度坐标。转换涉及到经纬度的计算,包括正弦、余弦、平方根和反正切等数学函数的应用。
摘要由CSDN通过智能技术生成
private static final double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
private static final double PI = 3.14159265358979324;

/**
  * @Discription: 百度坐标(bd09II)转火星坐标(GCJ02)
  * @Param lat  百度坐标纬度
  * @Param lon  百度坐标经度
  */
 public static Map<String, Double> baiduTomars(double lat, double lon) {
     Map<String, Double> mars_point = new HashMap<>();
     mars_point.put("lon", 0D);
     mars_point.put("lat", 0D);

     double x = lon - 0.0065;
     double 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);
     mars_point.put("lon", z * Math.cos(theta));
     mars_point.put("lat", z * Math.sin(theta));
     return mars_point;
 }

/**
  * @Discription: 火星坐标系(GCJ02)转百度坐标系(bd09II)
  * @Param gcjLat  火星坐标纬度
  * @Param gcjLon  火星坐标经度
  */
 public static Map<String, Double> marsTobaidu(double gcjLat, double gcjLon) {
     HashMap<String, Double> baidu_point = new HashMap<>();
     baidu_point.put("lon", 0D);
     baidu_point.put("lat", 0D);

     double x = gcjLon;
     double y = gcjLat;
     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);
     baidu_point.put("lon", z * Math.cos(theta) + 0.0065);
     baidu_point.put("lat", z * Math.sin(theta) + 0.006);
     return baidu_point;
 }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值