标签:for turn gcj cos orm 坐标 function float 百度
function baiduToWgs84(position){
var bdLon = position[0];
var bdLat = position[1];
var PI = 3.14159265358979324;
var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
var x = parseFloat(bdLon) - 0.0065;
var y = parseFloat(bdLat) - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
var gcjLon = z * Math.cos(theta);
var gcjLat = z * Math.sin(theta);
var a = 6378245.0;
var ee = 0.00669342162296594323;
var dLat = transformLat(gcjLon - 105.0, gcjLat - 35.0);
var dLon = transformLon(gcjLon - 105.0, gcjLat - 35.0);
var radLat = gcjLat / 180.0 * PI;
var magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * PI);
dLat = gcjLat - dLat;
dLon = gcjLon - dLon;
return [dLon,dLat];
}
function transformLon(x, y){
var PI = 3.14159265358979324;
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
return ret;
}
function transformLat (x,y){
var PI = 3.14159265358979324;
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
return ret;
}
标签:for turn gcj cos orm 坐标 function float 百度
原文地址:https://www.cnblogs.com/KaypoGeng/p/14949669.html