Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 获取地理位置授权

获取地理位置授权

<button  bindtap="getLocation" class="btnPhone {{lng !=''?'btnPhoneActive':''}}">获取地理位置</button>
// 获取地理位置开始
getLocation() {
var that = this
 wx.getLocation({
     success: function(res) {
         console.log("位置信息",res)
         app.globalData.lat = res.latitude;
         app.globalData.lon = res.longitude;
         that.setData({
           lng:res.longitude,
           lat:res.latitude
         })
         // post请求
         that.postInfo()
         wx.showToast({
           title: '获取位置成功!', // 标题
           icon: 'success',  // 图标类型,默认success
           duration: 1500  // 提示窗停留时间,默认1500ms
         })

     },
     fail() {
     wx.showModal({
         title: '提醒',
         content: '您拒绝了位置授权,将无法使用大部分功能,点击确定重新获取授权',
      success(res) {
      //如果点击确定
         if (res.confirm) {
             wx.openSetting({
               success(res) {
                 //如果同意了位置授权则userLocation=true
                 if (res.authSetting["scope.userLocation"]) {
               //    that.onLoad()
                 }
               }
             })
         }
      }
     })
     }
    })
},
// 获取地理位置结束
Edit this page
最近更新: 2025/12/2 01:46
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人