当前位置: 编程技术>java/j2ee
java实现百度坐标的摩卡托坐标与火星坐标转换的示例
来源: 互联网 发布时间:2014-11-04
本文导语: 这是百度地图的摩卡托坐标与火星坐标的相互转换方法,大家参考使用吧 代码如下:/** * 百度摩卡拖坐标与火星坐标的加密解密算法 * @author XFan * */public class Outer { private static double lat = 31.22997; private static double lon = 121.640756;...
这是百度地图的摩卡托坐标与火星坐标的相互转换方法,大家参考使用吧
代码如下:
/**
* 百度摩卡拖坐标与火星坐标的加密解密算法
* @author XFan
*
*/
public class Outer {
private static double lat = 31.22997;
private static double lon = 121.640756;
public static double x_pi = lat * lon / 180.0;
public static void main(String[] args) {
System.out.println("摩卡坐标经纬度:"+lat+","+lon);
System.out.println("火星坐标经纬度:"+bd_decrypt(lat,lon));
}
//解密成为火星坐标
public static String bd_decrypt(double bd_lat, double bd_lon)
{
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);
return gg_lat+","+gg_lon;
}
//加密成为摩卡托坐标
public static String bd_encrypt(double gg_lat, double gg_lon)
{
double x = gg_lon, y = gg_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 bd_lon = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
return gg_lat+","+gg_lon;
}
}