微信小程序将高德地图转为腾讯地图的自行车路线规划

微信小程序后台首页开发设置

相关文档

腾讯后台

在这里插入图片描述

微信小程序接入JDK

JDK腾讯地图文档

腾讯路线规划文档

核心代码

<map  id="myMap" ref="myMap" style="width: 100%; height: calc(100vh - 80px)"
          :latitude="latitude" :scale="scale" :longitude="longitude" @markertap="clickmarkertapfun"
          :polyline="polyline" :markers="covers" :circles="circles"></map>

///找到引入高德地图的地方替换JDK  替换key值
import amapFile from "../pluginsMap/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js";
// 更换腾讯地图
var myAmapFun = new amapFile({
  key: "腾讯地图key",
});

data() {
    return {
      detail: {},
      scale: 15, //地图缩放级别
      latitude: -1,
      longitude: -1,
      covers: [], //地图锚点
      coversList: [], //备用的锚点数据
      polyline: [], //路线规划容器
      circles: [],
      storeInfo: "",
    };
  },
//点击当前点位
clickmarkertapfun(e) {
      let id = e.detail.markerId;
      if (id <= 0) {
        return;
      }
      let storeInfo = this.coversList[id - 1];
      console.log(storeInfo);
      this.detail = {
        id: storeInfo.id,
        latitude: storeInfo.latitude,
        longitude: storeInfo.longitude,
      };
      console.log(this.detail);
      this.storeId = storeInfo.id;
      this.getMerchantBottomInfo();
      //起点
      let local = uni.getStorageSync(keys.mylocalhost);
      console.log("local >>", local);
      if (!local) return;
      uni.showLoading({
        title: "路线规划中",
      });
      myAmapFun.direction({
        mode: 'bicycling',
        from: {
          longitude: local.longitude,
          latitude: local.latitude
        },
        to: {
          longitude: this.detail.longitude,
          latitude: this.detail.latitude
        },
        success: function (res) {
          var ret = res;
          var coors = ret.result.routes[0].polyline, pl = [];
          //坐标解压(返回的点串坐标,通过前向差分进行压缩)
          var kr = 1000000;
          for (var i = 2; i < coors.length; i++) {
            coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
          }
          //将解压后的坐标放入点串数组pl中
          for (var i = 0; i < coors.length; i += 2) {
            pl.push({ latitude: coors[i], longitude: coors[i + 1] })
          }
          // console.log(pl, '你好')
          that.polyline = [
            {
              points: pl,
              color: "#0091ff",
              width: 6,
            },
          ];
          uni.hideLoading();
        },
      });
    },

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值