微信小程序通过腾讯地图规划路线 - Go语言中文社区

微信小程序通过腾讯地图规划路线


参考:https://blog.csdn.net/u011330225/article/details/74612620

index.wxml:
<map id="map" polyline="{{polyline}}" markers="{{markers}}" include-points="{{markers}}" style="width: 100%; height: 700rpx;"></map>


index.js:
var coors;
const config = require("../../utils/config.js");
var qqMapKey = config.qqMapSdk;
Page({
    data: {
        polyline:[],
        markers:[{
            latitude:23.362490,
            longitude:116.715790,
        }, {
            latitude:23.37228,
            longitude:116.75498,
        }],
    },
    onLoad: function (options) {
        let that2 = this;
        wx.request({
            url:'https://apis.map.qq.com/ws/direction/v1/driving/?from=23.362490,116.715790&to=23.37228,116.75498&output=json&callback=cb&key='+qqMapKey,
            success:function(res){
                coors = res.data.result.routes[0].polyline
                for(var i=2; i< coors.length; i++) {
                    coors[i]= coors[i-2]+ coors[i]/1000000
                }
                console.log(coors)
                //划线
                var b=[];
                for(var i=0; i< coors.length; i=i+2) {
                    b[i/2]={
                        latitude: coors[i],longitude:coors[i+1]
                    };
                    console.log(b[i/2])
                }
                that2.setData({
                    polyline: [{
                        points: b,
                        color:"#99FF00",
                        width:4,
                        dottedLine:false
                    }],
                })
            }
        })
    },
});

url 请求返回的详细信息:


返回路线:


版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_39461487/article/details/80238977
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-06-14 18:53:12
  • 阅读 ( 1185 )
  • 分类:职场

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢