1. 程式人生 > >小程序取消地理位置授權後,重新授權

小程序取消地理位置授權後,重新授權

進行 toa hset 加載 則無 技術 接口 -- modal

首次進入該頁面,調用wx.getLocation要求用戶進行授權;用戶拒絕後,再次進入該頁面,我們通過wx.getSetting接口,返回用戶授權的情況:

getLocation: function () {
    var that = this;
    //1、獲取當前位置坐標
    wx.getLocation({
      type: ‘wgs84‘,
      success: function (res) {
        wx.setStorageSync(‘latitude‘, res.latitude);
        wx.setStorageSync(
‘longitude‘, res.longitude); } }) },

1.展現步驟---取消獲取你的地理位置

技術分享圖片

2.再次彈出是否授權當前位置彈窗

技術分享圖片

3.授權所彈出界面

技術分享圖片

again_getLocation:function(){
    let that = this;
    // 獲取位置信息
    wx.getSetting({
      success: (res) => {
        console.log(res)
        if (res.authSetting[‘scope.userLocation‘] != undefined && res.authSetting[‘scope.userLocation‘] != true
) {//非初始化進入該頁面,且未授權 wx.showModal({ title: ‘是否授權當前位置‘, content: ‘需要獲取您的地理位置,請確認授權,否則無法獲取您所需數據‘, success: function (res) { console.log(res) if (res.cancel) { that.setData({ isshowCIty: false
}) wx.showToast({ title: ‘授權失敗‘, icon: ‘success‘, duration: 1000 }) } else if (res.confirm) { wx.openSetting({ success: function (dataAu) { console.log(dataAu) if (dataAu.authSetting["scope.userLocation"] == true) { wx.showToast({ title: ‘授權成功‘, icon: ‘success‘, duration: 1000 }) //再次授權,調用getLocationt的API that.getLocation(that); } else { wx.showToast({ title: ‘授權失敗‘, icon: ‘success‘, duration: 1000 }) } } }) } } }) } else if (res.authSetting[‘scope.userLocation‘] == undefined) {//初始化進入 that.getLocation(that); } else { //授權後默認加載 that.getLocation(that); } } }) },

小程序取消地理位置授權後,重新授權