微信小程序打開(kāi)目標(biāo)地址時(shí),偏差過(guò)遠(yuǎn)問(wèn)題
type:‘gcj02' 只對(duì)獲取當(dāng)前位置wx.getLocation方法生效
然后上網(wǎng)借鑒了大神的代碼,特意做個(gè)記錄
longitude,latitude為傳入的經(jīng)緯度坐標(biāo)
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