微信小程序-经纬度逆解析详细地址

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38023551/article/details/80736563

业务需求需要将经纬度解析为详细地址,去年使用的是百度地图,今年发现腾旭地图也更新了微信小程序的地图的接口;
1. http://lbs.qq.com/guides/startup.html
申请腾讯地图的key;
这里写图片描述
这里需要注意:
这里写图片描述
记得勾选微信小程序并填写正确的appid;其他的空着即可
2. 使用方法
文档地址http://lbs.qq.com/qqmap_wx_jssdk/index.html
使用方法

const QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
const wxMap = new QQMapWX({
  key: '****-GP***-RB***-B**US-****-RZ**Y' // 必填
});

 onShow () {
    /**经纬度逆解析 */
    this.reverseGeocoder()
  },

 /**经纬度逆解析 */
  reverseGeocoder() {
    const that = this;
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        wxMap.reverseGeocoder({
          location: {
            latitude: latitude,
            longitude: longitude
          },
          success: function (res) {
            const { city } = res.result.address_component
            console.log(city);
            that.setData({
              city,
            })
          },
        });
      },
      fail(res) {
        console.log(res)
      }
    })
  },

猜你喜欢

转载自blog.csdn.net/weixin_38023551/article/details/80736563
今日推荐