美文网首页
wx.openLocation 位置偏移不准确

wx.openLocation 位置偏移不准确

作者: 鹿简luz | 来源:发表于2022-12-05 10:29 被阅读0次

微信小程序打开目标地址时,偏差过远问题

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

相关文章

网友评论

      本文标题:wx.openLocation 位置偏移不准确

      本文链接:https://www.haomeiwen.com/subject/mxnbfdtx.html