分享

Web墨卡托坐标与WGS84经纬度互转 java代码

 nacy2012 2015-11-09
package Mypackage;

public class coordinate {
static double M_PI = Math.PI;
//经纬度转墨卡托
// 经度(lon),纬度(lat)
public static double[] lonLat2Mercator(double lon,double lat)
{
double[] xy = new double[2];

double x = lon *20037508.342789/180;

double y = Math.log(Math.tan((90+lat)*M_PI/360))/(M_PI/180);

y = y *20037508.34789/180;

xy[0] = x;
xy[1] = y;
return xy;
}

//墨卡托转经纬度

public static double[] Mercator2lonLat(double mercatorX,double mercatorY)
{
double[] xy = new double[2];
double x = mercatorX/20037508.34*180;

double y = mercatorY/20037508.34*180;

y= 180/M_PI*(2*Math.atan(Math.exp(y*M_PI/180))-M_PI/2);

xy[0] = x;
xy[1] = y;
return xy;

}
public static void main(String[] args)
{
double[] num;
num = lonLat2Mercator(120.385222,36.061416);
for(int i=0;i<num.length;i++)
{
System.out.println(num[i]);
}
// num = Mercator2lonLat(13401221.612075035,4309075.414032666);
// for(int i=0;i<num.length;i++)
// {
// System.out.println(num[i]);
// }
}


}


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多