• 高德地图驾车导航使用


    高德地图驾车导航使用

    传入起点终点 返回路线长度,耗时,路线规划

    function (lon, lat) {
        var destination = [lon, lat];
        var index = layer.msg("查询中....", {time: 0, shade: 0.01})
        $.ajax({
            //起始位置, 结束位置,结果控制    速度优先
            url: "https://restapi.amap.com/v3/direction/driving?key=你自己的key&origin=" + location + "&destination=" + destination + "&extensions=base&strategy=0",
            type: 'get',
            dataType: 'json',
            success: function (res) {
                layui.layer.close(index);
                //正常返回且唯一一条数据
                if (res.status == "1" && res.info == "OK" && res.count == "1") {
                    var steps = res.route.paths[0].steps;
                    //线条
                    var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0, 0.8]), 2);
                    var layer = map.getLayer("navigateLayer");
                    layer.setVisibility(true);
                    //清空上次数据
                    layer.clear();
                    for (var i = 0; i < steps.length; i++) {
                        var polylineArray = new Array();
                        //;切割字符串位置
                        var array = steps[i].polyline.split(";");
                        for (var j = 0; j < array.length; j++) {
                            //分割数组
                            polylineArray.push(array[j].split(","));
                        }
                        var polyline = new Polyline(polylineArray, wgs);
                        var gra = new Graphic(polyline, lineSymbol, res.route);
                        layer.add(gra);
                    }
                    var height = "32";
                    var width = "32";
                    var symbolImage = {
                        // "url": ctx + "assets/images/map/waterQuantityStation1.png",
                        "url": ctx + "assets/images/map/end.png",
                        "width": width,
                        "height": height,
                        "angle": 0
                    };
                    var pointSymbol = new PictureMarkerSymbol(symbolImage);
                    var endPoint = new Point(res.route.destination.split(",")[0], res.route.destination.split(",")[1]);
                    var end = new Graphic(endPoint, pointSymbol, res.route.paths[0]);
                    map.setZoom(10);
                    layer.add(end);
                    customInfoWindow.openInfoWindow(endPoint, end);
    
    
                }
    
            }
        })
    }
    
    作者: JaminYe
    版权声明:本文原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
  • 相关阅读:
    lintcode395-硬币排成线 II
    lintcode-394-硬币排成线
    lintcode-392-打劫房屋
    lintcode-391-数飞机
    lintcode-389-判断数独是否合法
    lintcode-387-最小差
    lintcode-384-最长无重复字符的子串
    lintcode-383-装最多水的容器
    lintcode-382-三角形计数
    爬虫笔记:初始爬虫(二)
  • 原文地址:https://www.cnblogs.com/JaminYe/p/13387970.html
Copyright © 2020-2023  润新知