是不是直接调用wx.openLocation,不会弹出授权框啊,我试了三个手机都没弹,为啥官方文档里说需要授权呢

是不是直接调用wx.openLocation,不会弹出授权框啊,我试了三个手机都没弹,为啥官方文档里说需要授权呢

阅读 4.9k
2 个回答

小程序前段时间好像更新了,现在调用类似的接口都需要先主动邀请用户授权,小程序不会主动拉起授权了现在,你先使用wx.getSetting,在成功的时候再调用openLocation试试
在你的地图地图图标外面加一层button
<button open-type="openSetting" bindtap="onGotSetting">打开授权设置页</button>
然后在page里面写

onGotSetting:function(){
    wx.getSetting({
    success(res) {
        if (!res.authSetting['scope.userLocation']) {
            wx.authorize({
                scope: 'scope.userLocation',
                success() {
                    wx.getLocation({
                      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
                      success: function(res) {
                            //你的操作
                        })
                      }
                    })
                })
            }
        }
    })
}

先利用getSetting查看用户是否授权,没有的话吊起授权窗口,现在一般都有button

wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
            wx.authorize({
              scope: 'scope.userLocation',
              success(res) {
              }
            })
          }
      }
    })
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题