3499关注10519浏览
再次授权定位。返回后不执行wx.getLocation方法,获取不到定位
onReady: function () {
var that = this;
wx.getSetting({
success: (res) => {
console.log(res);
console.log(res.authSetting['scope.userLocation']);
if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {//非初始化进入该页面,且未授权
console.log("没授权")
wx.showModal({
title: '是否授权当前位置',
content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
success: function (res) {
if (res.cancel) {
console.info("1授权失败返回数据");
} else if (res.confirm) {
wx.openSetting({
success: function (data) {
console.log(data);
if (data.authSetting["scope.userLocation"] == true) {
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 5000
})
//再次授权,调用getLocationt的API
that.posit(that);
} else {
wx.showToast({
title: '授权失败',
icon: 'success',
duration: 5000
})
}
}
})
}
}
})
} else if (res.authSetting['scope.userLocation'] == undefined) {//初始化进入
that.posit(that);
}
}
})
}
在开发工具上是执行wx.getLocation方法的,在手机上就不执行
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多> -
疯人院门开了
17人对此回答表示赞同
返回不执行onReady方法,还有wx.openSetting()即将废弃,请尽早适配。
展开170回复分享发布于 6年前评论(0)
收起评论