微信小程序打开目标地址时,偏差过远问题
type:‘gcj02' 只对获取当前位置wx.getLocation方法生效
然后上网借鉴了大神的代码,特意做个记录
longitude,latitude为传入的经纬度坐标
transLocation(longitude,latitude){
let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
let x = longitude - 0.0065;
let y = latitude - 0.006;
let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
let wz = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
let lon = z * Math.cos(wz);
let lat = z * Math.sin(wz);
wx.openLocation({
longitude: lon,
latitude: lat,
})
},
大神原文:https://blog.csdn.net/m0_58819270/article/details/117519111