你瞅啥呢

2022-08-24 wx.getLocation报"errCode":2"错误

前言:微信小程序项目使用到wx.getLocation接口,在真机测试时,小程序的位置信息开启了【使用小程序时】即获取定位信息时,用户手动关闭了定位授权,会导致wx.getLocation拿不到位置信息,报错:

{errMsg: "getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF", errCode: 2}

注:开发工具测试没有测出这个bug。

解决方案:

      wx.getLocation({
        //获取地址经纬度
        type: 'wgs84',
        complete(e) {
          console.log('获取地址完成:');
          console.log(e);
          if (e.errCode == 2) {
            alert("请打开定位授权");
    
          } else {
            this.idata = e;
          }
        },
      })

 

posted @ 2022-08-25 09:41  叶乘风  阅读(1070)  评论(0)    收藏  举报