获取地理位置失败!
发布于 6 年前 作者 yangshen 296 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现

能获取地理位置;能清除缓存;能打开设置

  • 复现路径

    let self = this

    wx.getLocation({

      type: ‘gcj02’, //返回可以用于wx.openLocation的经纬度

      success: function (res) {

        var latitude = res.latitude

        var longitude = res.longitude

        self.setData({

          lat: res.latitude,

          lng: res.longitude,

        })

        console.log(“获取位置”,latitude,longitude);

        self.getNearShop(latitude, longitude)

      },

      fail: function(e) {

        console.log(‘获取位置失败’);

        wx.showModal({

          title: ‘获取地理位置失败’,

          content: ‘请允许爽电使用您的位置信息’,

          confirmText: “设置”,

          showCancel: false,

          success: function(res) {

            if (res.confirm) {

              console.log(‘用户点击确定’);

              wx.openSetting({

                success: function() {

                  console.log(12345);

                  self.getLocation();

                }

              })              

            } else if (res.cancel) {

              console.log(‘用户点击取消’)

            }

          }

        })

      }

    });  

  • 提供一个最简复现 Demo
1 回复

应前台该是异步的问题,通过this.setData()可以向发送数据,但是后台需要考虑异步操作,我也遇到了这样的问题

回到顶部