问题:后端给的gps,前端用高德地图渲染,绘制出来的轨迹有偏移,没有在道路上

1.坐标系转换方法一
地址:https://blog.csdn.net/weixin_34049948/article/details/90619608
var WGS84_to_GCJ02 = function() {}
WGS84_to_GCJ02.prototype.a = 6378245.0;
WGS84_to_GCJ02.prototype.ee = 0.00669342162296594323;
WGS84_to_GCJ02.prototype.transform = function(wgLat, wgLon) {
if (this.outOfChina(wgLat, wgLon)) {
return [wgLat, wgLon];
}
dLat = this.transformLat(wgLon - 105.0, wgLat - 35.0);
dLon = this.transformLon(wgLon - 105.0, wgLat - 35.0);
radLat = wgLat / 180.0 * Math.PI;
magic = Math.sin(radLat);
magic = 1 - this.ee * magic * magic;
sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((this.a * (1 - this.ee)) / (magic * sqrtMagic) * Math.PI);
dLon = (dLon * 180.0) / (this.a / sqrtMagic * Math.cos(radLat) * Math.PI);
mgLat = wgLat + dLat;
mgLon = wgLon

本文介绍了如何通过两种方法将WGS84坐标转换为高德地图坐标,以解决后端GPS数据在前端渲染时的偏移问题,包括坐标系转换公式和判断是否在国内的函数。

3659

被折叠的 条评论
为什么被折叠?



