• 高德地图驾车导航使用


    高德地图驾车导航使用

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

    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 版权协议,转载请附上原文出处链接和本声明。
  • 相关阅读:
    Javascript 组成:ECMAscript、Dom、Bom
    js字符串的操作
    函数(方法)基本内容
    for循环运用,三角形
    Java Script 数组
    控制语句—for循环、while循环
    JavaScript基础内容
    网站创建中遇到的问题
    数据库无法启动ORA-01034: ORACLE not available
    关于数据库管理员安全和权限
  • 原文地址:https://www.cnblogs.com/JaminYe/p/13387970.html
Copyright © 2020-2023  润新知