wx.getLocation不能获取位置坐标

发布于 7 年前作者 fengxiuying422 次浏览最后编辑 7 年前来自 ask
  • 当前 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

})

}

})

},

WXOPEN Club 内容图片

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

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

  • 预期表现

正常获取用户位置

  • 复现路径

  • 提供一个最简复现 Demo

2 回复
taomeng
taomeng1 楼6 年前

fail 的 errmsg 是?

yang50
yang502 楼5 年前
WXOPEN Club 内容图片

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