jsmx java,Js /Java经纬度墨卡托转换

一、Js方法

墨卡托转经度

function getMercatorLon(x){

return x/20037508.34*180;

}

墨卡托转纬度

function getMercatorLat(y){

y = y/20037508.34*180;

return 180/Math.PI*(2*Math.atan(Math.exp(y*Math.PI/180))-Math.PI/2);

}

经度转墨卡托

function getMercatorLon(x){

return x * 20037508.34 / 180;

}

纬度转墨卡托

function getMercatorLat(y){

y = Math.log(Math.tan((90 + y) * Math.PI / 360)) / (Math.PI / 180);;

return y* 20037508.34 / 180;

}

二、Java方法

/**

* 经度转墨卡托

* @param x 经度

* @return 墨卡托经度

*/

public static double getMercatorLon(double x) {

try {

double mx = x * 20037508.34 / 180;

return mx;

}

catch (BaseException e) {

throw new BaseException(e, LOG);

}

}

/**

* 纬度转墨卡托

* @param y 纬度

* @return 墨卡托纬度

*/

public static double getMercatorLat(double y) {

try {

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

my = my * 20037508.34 / 180;

return my;

}

catch (BaseException e) {

throw new BaseException(e, LOG);

}

}

/**

* 墨卡转托经度

* @param x 墨卡托经度

* @return 经度

*/

public static double getLonMercator(double x) {

try {

// double mx = x * 20037508.34 / 180;

double mx = x / 20037508.34 * 180;

return mx;

}

catch (BaseException e) {

throw new BaseException(e, LOG);

}

}

/**

* 墨卡托转纬度

* @param y 墨卡托纬度

* @return 纬度

*/

public static double getLatMercator(double y) {

try {

double my = y / 20037508.34 * 180;

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

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

// my = my * 20037508.34 / 180;

return my;

}

catch (BaseException e) {

throw new BaseException(e, LOG);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值