wx.getLocation不能获取位置坐标
发布于 6 年前 作者 fengxiuying 285 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

onLoad: function (options) {

wx.getSetting({

success(res) {

console.log(res);

console.log(res.authSetting[‘scope.userLocation’]);

if (!res.authSetting[‘scope.userLocation’]) {

wx.authorize({

scope: ‘scope.userLocation’,

success() {

// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问

wx.showToast({

title: ‘授权成功’,

icon: ‘success’,

duration: 2000

})

wx.getLocation

},

fail:function(){

wx.showToast({

title: ‘授权失败’,

icon: ‘success’,

duration: 2000

})

}

})

}else

{

wx.showToast({

title: ‘fail已经授权’,

icon: ‘success’,

duration: 2000

})

}

}

})

},

getPos:function(){

let that=this;

console.log(‘执行getPos方法’);

wx.getLocation({

type: ‘wgs84’,

success(res) {

that.setData({

x: res.latitude,

y: res.longitude

})

}

})

},

  测试手机:华为荣耀V9 play 【安卓7.0】

代码如上,手机设置上检测用户是否授权获取位置时,直接回调了fail,无法获取用户位置,开发工具中一切正常

  • 预期表现

正常获取用户位置

  • 复现路径
  • 提供一个最简复现 Demo
2 回复

fail 的 errmsg 是?

当微信获取位置的权限被阻止后,wx.getSetting仍然执行的是success,由于如图所示的值是ture  执行了else  弹出已经授权,但实际上微信位置是不能获取的【在手机上】

回到顶部