微信授权

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html

新授权获取用户信息

js

 onGetUserInfo(e){
    wx.getUserProfile({
    desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
    success: (res) => {
        this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
        })
    }
})
 }

map地图的使用

json

1.在app.json中添加

"permission": {
        "scope.userLocation": {
        "desc": "你的位置信息将用于小程序位置接口的效果展示"
        }
    }

js

2.调用地理定位接口

wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        console.log(res);
      }
    });
    返回值
    accuracy: 65
    buildingId: ""
    direction: -1
    errMsg: "getLocation:ok"
    floorName: "1000"
    horizontalAccuracy: 65
    latitude: 34.82350540161133
    longitude: 113.64183807373047
    provider: "gps"
    speed: -1
    verticalAccuracy: 10

html

3.地图组件 (需要用getLocation获取经纬度)

<map longitude="{{longitude}}" latitude="{{latitude}}"></map>

微信小程序之逆地址解析

同地图的显示,需要配置app.json中的permission
onLoad: function () {
    let self = this;
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        console.log(latitude, longitude);
        let key = "6ESBZ-MQECU-BVFVV-4O5A3-J3ZH2-OUBDU"
        self.getCityInfo(latitude, longitude, key)
      },
      fail(error) {
        throw new Error("获取位置信息失败...")
      }
    })
  },

getCityInfo(lat, lng, mapKey, callback) {
    let self = this;
    // 逆位置解析
    // https://lbs.qq.com/webservice_v1/guide-gcoder.html
    wx.request({
      url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=${mapKey}`,
      success: res => {
        console.log(res.data.result);
      }
    })
  }

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容