微信小程序 map地图授权

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

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值