网上搜索出镜率高的是这个函数,但用在地图上有几米的误差。
bdTogcj(lat, lng) {//坐标第转换
let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
let x = lng - 0.0065;
let y = lat - 0.006;
let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
let g2_lnn = z * Math.cos(theta);
let g2_lat = z * Math.sin(theta);
return [g2_lat,g2_lnn];
}
从npm上搜到个star很高的这个,试了下,几乎0误差。
GitHub - wandergis/coordtransform: 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
coordtransform - npm