mpvue小程序获取地理位置

  //  获取用户地址
    getLocation(){
      wx.getSetting({
        success: function(e) {
          console.log(e.authSetting["scope.userLocation"]);
          let userLocation = e.authSetting["scope.userLocation"];
          if(typeof(userLocation)=="undefined"){  // 用户第一次授权地理位置
              //1、获取当前位置坐标
            wx.getLocation({
              type: 'wgs84',
              success: res => {
                //2、根据坐标获取当前位置名称,显示在顶部:逆地址解析
                that.address = res.latitude+','+res.longitude;
              }
            })
          }else{  // 用户点了允许授权之后 又设置不允许获取位置的处理
         
          }
        }
      })
    }

猜你喜欢

转载自blog.csdn.net/Follow_the_heart/article/details/88645543