关于微信小程序连接腾讯地图的介绍

关于微信小程序连接腾讯地图的介绍

直接上代码

var global = getApp();
var o = global.globalData.siteInfo.siteUrl;
var i = require("../../common/common.js");
var QQMapWX = require(‘../../utils/qqmap-wx-jssdk.min‘);
var qqmapsdk;
  onLoad: function (k) {

    // 实例化API核心类
    qqmapsdk = new QQMapWX({
      key: ‘P7DBZ-V7MC4-OQBUH-X36F6-35YKH-BLBUQ‘
    });
  },onShow: function () {
    // 调用接口
    var that = this;
    wx.getLocation({
      type: ‘gcj02‘,
      altitude: ‘true‘,
      success: function (res) {
        console.log(res)
        //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          }, //坐标
          get_poi: 0, //是否获取坐标对应附近列表
          poi_options: ‘policy=2;radius=3000;page_size=10;page_index=1‘, //poi 参数
          success: function (res) {
            var address = res.result.address_component;
            console.log(res.result.address_component, "???????????")
            that.setData({
              province:address.province,
              city:address.city,
            });
            if(that.data.province != null && that.data.city != null) {
              wx.request({
                url: o + "API/IndexMini/get_local",
                data: {
                  applet_id: global.globalData.uniacid,
                  city: address.city[0] + address.city[1]
                },
                success: function (e) {
                  console.log(e.data.data, "11111111111");
                  that.setData(
                    {
                      your_city: e.data.data
                    }
                  )
                }

              })
            }

          }
        })
      }
    });
   },

最后千万不要忘记了在微信的管理工具中添加上腾讯地图的接口地址

https://apis.map.qq.com

关于微信小程序连接腾讯地图的介绍

上一篇:微信小程序如何进行本地调试


下一篇:小程序秒杀倒计时