小程序wx.getLocation定位

3499关注10503浏览

再次授权定位。返回后不执行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方法的,在手机上就不执行


展开全部
收起
1回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • 疯人院门开了

    17人对此回答表示赞同

    返回不执行onReady方法,还有wx.openSetting()即将废弃,请尽早适配。

    展开
    17
    0回复
    发布于 5年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部