java完成百度坐標的摩卡托坐標與火星坐標轉換的示例。本站提示廣大學習愛好者:(java完成百度坐標的摩卡托坐標與火星坐標轉換的示例)文章只能為提供參考,不一定能成為您想要的結果。以下是java完成百度坐標的摩卡托坐標與火星坐標轉換的示例正文
這是百度地圖的摩卡托坐標與火星坐標的互相轉換辦法,年夜家參考應用吧
/**
* 百度摩卡拖坐標與火星坐標的加密解密算法
* @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;
}
}