微信小程序map地图授权

    xiaoxiao2022-07-05  232

    小程序  在开发授权方面的问题:

    1.当用户拒绝了授权的情况下,如何再次获得权限 

       小程序更新后,不在支持调用接口方式(https://developers.weixin.qq.com/community/develop/doc/0000a26e1aca6012e896a517556c01)

     

    解决办法:

    wxml:

    <view class='layer-mask' wx:if="{{isLayer}}"> <view class='layer-tips'> <view class='title'>提示</view> <view class='desc'>若不开启位置授权,则无法签到</view> <!-- 授权按钮 --> <van-button size="large" open-type="openSetting" bind:opensetting="bind:opensetting" class='btn'>确定</van-button> </view> </view>

     

    js:

    //显示时调用一次 onShow() { let that = this; wx.showLoading({ title:"加载中...." }); //获取地址 const getAddress = new Promise((resolve, reject) => { that.loadAddress(function (res) { resolve(res); return res; }) }).then((res) => { //获取完成执行 that.getPoject(res); }) }, //获取地址 loadAddress(callback){ var that = this; wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: function (res) { //控制弹窗是否显示 that.setData({ isLayer: false }) wx.showLoading({ title: "加载中...." }); var latitude = res.latitude//维度 var longitude = res.longitude//经度 console.log(res); let data = that.data; data.markers[0].latitude = latitude; data.markers[0].longitude = longitude; let param={ location: latitude + "," + longitude, key:"*******************************" } //key值 到腾讯去注册申请(https://lbs.qq.com/webservice_v1/guide-geocoder.html) //接口请求url (https://apis.map.qq.com/ws/geocoder/v1/) recordModel.getRecordMap(param).then((result)=>{ data.markers[0].address = result.result.address; callback(data) }) }, fail:function(){ wx.hideLoading(); //当用户拒绝了授权情况下,显示弹窗 用按钮去获取授权 console.log("用户拒绝了授权"); that.setData({ isLayer:true }) } }) }, //获取权限 getSettingLocation(){ console.log("授权调用") let that=this; wx.getSetting({ success(res) { if (!res.authSetting['scope.userLocation']) { wx.authorize({ scope: 'scope.userLocation', success() { // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问 console.log(333334444) // wx.startRecord() }, fail(){ console.log("授权调用失败"); // that.getSettingLocation(); } }) } } }) },

     

    最新回复(0)