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;
}
百度坐标 火星坐标 相互转换
于 2023-05-17 17:12:06 首次发布
这篇文章提供了两个Java方法,分别用于将百度坐标(bd09II)转换为火星坐标(GCJ02),以及反过来,从火星坐标到百度坐标。转换涉及到经纬度的计算,包括正弦、余弦、平方根和反正切等数学函数的应用。
摘要由CSDN通过智能技术生成