当前位置:首页 > 小程序 > 正文内容

小程序授权

tigon4年前 (2021-08-19)小程序2949
export function isAuthLocation() {
  return new Promise((resolve, reject) => {
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              console.log('这里是点击确认按钮授权成功后操作???');
              wx.getLocation({
                isHighAccuracy: true,
                success(res) {
                  resolve(res)
                },
              });
            },
            fail() {
              console.log('这里是拒绝的操作');
              resolve('1')
            }
          })
        }else {
          console.log('授权过了');
          wx.getLocation({
            isHighAccuracy: true,
            success(res) {
              resolve(res)
            },
            fail() {
              resolve('2')
            }
          });
        }
      }
    })
  })
}

版权声明:本文由Web学习之路发布,如需转载请注明出处。

本文链接:https://www.webge.net/?id=132

返回列表

上一篇:主动打开手机定位功能

没有最新的文章了...

“小程序授权” 的相关文章

小程序-- wx.switchTab({url}) 跳转页面

wx.switchTab({url}) 传页面page地址 注意,页面会刷新,那下面导航如何选中呢? 1,在app.js里定义全局变量 globalData: { selected: 0, }, 2,每个页面引入全局变量 getApp().globalData.se...

小程序自定义下拉刷新

<scroll-view style='height:100%' scroll-y='{{!isindrag}}' bindscroll='scorll'> <view class='column' bindtouc...

小程序列表展开收起功能

小程序列表展开收起功能

index.wxml <block wx:for-items="{{list}}" wx:key="{{item.id}}"> <view class="kind-list-item"> <...

小程序多层展示收起

小程序多层展示收起

<view class='list_box' wx:for='{{list}}' wx:key='this' wx:for-item='parentItem' wx:for-index='parentIndex'...

小程序页面开启下拉刷新不回弹问题

onPullDownRefresh: function () { // 停止下拉动作 wx.stopPullDownRefresh(); //添加这句就可以了 if(this.data.searchContent){ this.setSearchListDataFn(th...

小程序 a到b到c ,从c直接回到a

1A页面跳转到B wx.navigateTo({ url: `/pages/signUp/A` }) 2,B页面到C wx.navigateTo({ url: `/pages/signUp/C` }) 从c加到A页面 在c页面写 onUnload: fun...