微信小程序定位權(quán)限申請(qǐng)多次被拒解決思路

如果在小程序中需要使用定位相關(guān)的操作赁咙,前提是需要在小程序后臺(tái)進(jìn)行申請(qǐng)開通


申請(qǐng)頁(yè)

但是這個(gè)"獲取當(dāng)前的地理位置灭衷、速度"的權(quán)限申請(qǐng)的通過率比較低毅否,有的開發(fā)朋友可能會(huì)來(lái)來(lái)回回折騰十幾次甚至幾十次仍然未通過显拳,這里提供一個(gè)快速申請(qǐng)通過的新思路窿克,經(jīng)過測(cè)試棕硫,"打開地圖選擇位置"接口權(quán)限的通過率遠(yuǎn)遠(yuǎn)高于"獲取當(dāng)前的地理位置髓涯、速度",而且"打開地圖選擇位置"同時(shí)也就獲取了定位權(quán)限。所以可以曲線救國(guó)哈扮,多申請(qǐng)一個(gè)權(quán)限即可纬纪。
下面我將提供一個(gè)符合"打開地圖選擇位置"的頁(yè)面,可以用來(lái)應(yīng)付審核滑肉。
大概頁(yè)面樣式如下:


門店頁(yè)

代碼實(shí)現(xiàn):

storeMap.wxml
<!--pages/storeMap/storeMap.wxml-->
<view class="main" style="height:{{mapHeight}}px;">
  <map class="map" style="height:{{mapHeight}}px;" id="map" longitude="{{location.longitude}}" latitude="{{location.latitude}}" markers="{{markers}}" bindmarkertap="makertap" bindregionchange="regionchange" show-location>
    <cover-view class="map-cover">
      <cover-image class="map-cover-img" src="../../image/icon-location.png" catchtap="setUserLocation"></cover-image>
    </cover-view>
    <cover-view class="map-cover-5" catchtap="" wx-if="{{showChoosedStoreInfo}}" catchtap="aedDetail">
      <cover-image class="choosed-store-info-img" src="https://img1.baidu.com/it/u=1070662155,3808653193&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1669309200&t=d42000cb6ada37face9f0ec85e48aa21"></cover-image>
      <cover-image class="choosed-store-info-icon" src="../../image/current-location.png"></cover-image>
      <cover-view class="choosed-store-info-detail">{{choosedStore.title}}</cover-view>
      <cover-view class="choosed-store-info-button" catchtap="goThere">去店里</cover-view>
    </cover-view>
  </map>
</view>
storeMap.js
// pages/storeMap/storeMap.js
Page({

  /**
   * 頁(yè)面的初始數(shù)據(jù)
   */
  data: {
    mapHeight: 0,
    markers:[],
    //默認(rèn)的門店信息包各,如果有需要,可以從接口獲取
    markersDefault: [{
        iconPath: "../../image/ic_store.png",
        id: 1,
        longitude: 121.523315,
        latitude: 31.292936,
        width:30,
        height:30,
        title: "楊浦區(qū)五角場(chǎng)店"
      },{
        iconPath: "../../image/ic_store.png",
        id: 2,
        longitude: 116.375381,
        latitude: 40.025043,
        width:30,
        height:30,
        title: "北京奧林匹克運(yùn)動(dòng)會(huì)店"
      },{
        iconPath: "../../image/ic_store.png",
        id: 3,
        longitude: 114.115030,
        latitude: 22.537600,
        width:30,
        height:30,
        title: "深圳萬(wàn)象城門店"
      },{
        iconPath: "../../image/ic_store.png",
        id: 4,
        longitude: 121.803829,
        latitude: 31.136933,
        width:30,
        height:30,
        title: "上海浦東國(guó)際機(jī)場(chǎng)店"
      },{
        iconPath: "../../image/ic_store.png",
        id: 5,
        longitude: 121.447288,
        latitude: 31.146777,
        width:30,
        height:30,
        title: "上海植物園店"
      }
    ],
    location:{},
    showChoosedStoreInfo: false, // 顯示選中的門店信息
    choosedStore: {},
  },


  /**
   * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
   */
  onLoad(options) {
    //初始化屏幕信息
    wx.getSystemInfo({
      complete: (sysinfo) => {
        console.log(sysinfo);
        let height = sysinfo.windowHeight;
        this.setData({
          mapHeight: height
        })
      },
    })

    this.getLocationMethod();
  },


  /**
   * 獲取當(dāng)前位置信息
   */
  getLocationMethod: function () {
    var that = this;
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var lat = res.latitude;
        var lon = res.longitude;
        var selfMarker = {
          iconPath: "../../image/current-location.png",
          id: 0,
          latitude: res.latitude,
          longitude: res.longitude,
          width: 30,
          height: 30,
          title: ' 我的當(dāng)前位置 '
        }
        var tempList = [];
        for (var i = 0; i < that.data.markersDefault.length; i++) {
          tempList.push(that.data.markersDefault[i]);
        }
        tempList.push(selfMarker);

        that.setData({
          mapScale: '14',
          location: {
            longitude: res.longitude,
            latitude: res.latitude
          },
          markers: tempList
        })
        //在獲取當(dāng)前位置信息之后赦邻,請(qǐng)求獲取周圍aed信息的接口髓棋,獲取信息
        // that.getStoreInfo(res);
      },
      fail: function (res) {
        if (res.errMsg == 'getLocation:fail auth deny') {
          wx.showModal({
            title: '',
            content: '需要授權(quán)定位才能使用此功能',
            success: function (res) {
              if (res.confirm) {
                wx.openSetting({
                  success: (res) => {
                    if (res.authSetting['scope.userLocation']) {
                      that.getLocationMethod();
                    }
                  }
                })
              }
            }
          })
        }
      },
      complete: function (res) {},
    })
  },

  makertap: function (e) {
    var that = this;
    var id = e.markerId;
    if (id == 0){
      that.setData({
        showChoosedStoreInfo: false,
        choosedStore : {}
      })
    }
    for (var i = 0; i < that.data.markersDefault.length; i++) {
      if(that.data.markersDefault[i].id == id){
          that.setData({
            showChoosedStoreInfo: true,
            choosedStore : that.data.markersDefault[i]
          })
      }
    }

  },

  goThere: function () {
    wx.openLocation({
      latitude: parseFloat(this.data.choosedStore.latitude),
      longitude: parseFloat(this.data.choosedStore.longitude),
      name: this.data.choosedStore.title,
      scale: 28
    })
  },

  /**
   * 回到當(dāng)前位置
   */
  setUserLocation: function () {
    console.log("回到當(dāng)前位置");
    var mapCtx = wx.createMapContext('map')
    mapCtx.moveToLocation() //地圖回到當(dāng)前位置
  },
  /**
   * 生命周期函數(shù)--監(jiān)聽頁(yè)面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁(yè)面顯示
   */
  onShow() {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁(yè)面隱藏
   */
  onHide() {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁(yè)面卸載
   */
  onUnload() {

  },

  /**
   * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
   */
  onPullDownRefresh() {

  },

  /**
   * 頁(yè)面上拉觸底事件的處理函數(shù)
   */
  onReachBottom() {

  },

  /**
   * 用戶點(diǎn)擊右上角分享
   */
  onShareAppMessage() {

  }
})
storeMap.json
{
  "usingComponents": {},
  "navigationBarTitleText": "門店地圖"
}
storeMap.wxss
/* pages/storeMap/storeMap.wxss */
.main {
  width: 100%;
}

.map {
  width: 100%;
  position: absolute;
}

.map-cover {
  width: 120rpx;
  height: 160rpx;
  border-radius: 5rpx;
  position: absolute;
  bottom: 300rpx;
  right: 40rpx;
}

.map-cover-img {
  width: 120rpx;
  height: 120rpx;
  border-radius: 20rpx;
  overflow: hidden;
  margin: 20rpx 0;
}

.map-cover-5 {
  width: 80%;
  height: 200rpx;
  border-radius: 20rpx;
  position: absolute;
  bottom: 0rpx;
  margin: 0 auto;
  background: white;
  margin: 10%;
}

.choosed-store-info-img {
  width: 200rpx;
  height: 160rpx;
  float: left;
  margin-left: 20rpx;
  margin-top: 20rpx;
  border-radius: 10rpx;
  overflow: hidden;
}

.choosed-store-info-icon {
  width: 40rpx;
  height: 40rpx;
  margin-top: 20rpx;
  margin-left: 240rpx;
}

.choosed-store-info-detail {
  height: 60rpx;
  color: #666666;
  font-size: 32rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: keep-all;
  margin-top: -40rpx;
  margin-left: 300rpx;
  margin-right: 10rpx;
  word-break: break-all;
  word-wrap: break-word;
  white-space: pre-line;
}

.choosed-store-info-button {
  height: 60rpx;
  width: 240rpx;
  font-size: 32rpx;
  overflow: hidden;
  line-height: 60rpx;
  text-align: center;
  color: #ffffff;
  border-radius: 10rpx;
  text-overflow: ellipsis;
  word-break: keep-all;
  margin-top: 20rpx;
  margin-left: 300rpx;
  margin-right: 10rpx;
  word-break: break-all;
  word-wrap: break-word;
  white-space: pre-line;
  background: #FF9525;
}

上面用到的icon比較簡(jiǎn)單,大家自行尋找替換即可惶洲。沒其他多余的代碼按声,只需要提供一個(gè)入口,跳轉(zhuǎn)到storeMap頁(yè)面即可恬吕,入口UI大家自行設(shè)計(jì)

  storeMap() {
    wx.navigateTo({
      url: '../storeMap/storeMap',
    })
  },

完成以上签则,編譯后截圖,拿著截圖去申請(qǐng)"打開地圖選擇位置"和"獲取當(dāng)前的地理位置铐料、速度"權(quán)限渐裂,分分鐘通過。親測(cè)有效钠惩,3分鐘審核通過柒凉!通過后,干掉以上代碼即可

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末篓跛,一起剝皮案震驚了整個(gè)濱河市膝捞,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌愧沟,老刑警劉巖蔬咬,帶你破解...
    沈念sama閱讀 219,589評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異沐寺,居然都是意外死亡林艘,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,615評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門混坞,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)狐援,“玉大人,你說(shuō)我怎么就攤上這事」敬澹” “怎么了场钉?”我有些...
    開封第一講書人閱讀 165,933評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵蚊俺,是天一觀的道長(zhǎng)懈涛。 經(jīng)常有香客問我,道長(zhǎng)泳猬,這世上最難降的妖魔是什么批钠? 我笑而不...
    開封第一講書人閱讀 58,976評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮得封,結(jié)果婚禮上埋心,老公的妹妹穿的比我還像新娘。我一直安慰自己忙上,他們只是感情好拷呆,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,999評(píng)論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著疫粥,像睡著了一般茬斧。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上梗逮,一...
    開封第一講書人閱讀 51,775評(píng)論 1 307
  • 那天项秉,我揣著相機(jī)與錄音,去河邊找鬼慷彤。 笑死娄蔼,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的底哗。 我是一名探鬼主播岁诉,決...
    沈念sama閱讀 40,474評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼跋选!你這毒婦竟也來(lái)了涕癣?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,359評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤野建,失蹤者是張志新(化名)和其女友劉穎属划,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體候生,經(jīng)...
    沈念sama閱讀 45,854評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡同眯,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,007評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了唯鸭。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片须蜗。...
    茶點(diǎn)故事閱讀 40,146評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出明肮,到底是詐尸還是另有隱情菱农,我是刑警寧澤,帶...
    沈念sama閱讀 35,826評(píng)論 5 346
  • 正文 年R本政府宣布柿估,位于F島的核電站循未,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏秫舌。R本人自食惡果不足惜的妖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,484評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望足陨。 院中可真熱鬧嫂粟,春花似錦、人聲如沸墨缘。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,029評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)镊讼。三九已至宽涌,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間狠毯,已是汗流浹背护糖。 一陣腳步聲響...
    開封第一講書人閱讀 33,153評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留嚼松,地道東北人嫡良。 一個(gè)月前我還...
    沈念sama閱讀 48,420評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像献酗,于是被迫代替她去往敵國(guó)和親寝受。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,107評(píng)論 2 356

推薦閱讀更多精彩內(nèi)容