码迷,mamicode.com
首页 > 其他好文 > 详细

百度地图 驾车路线编辑粗浅实例

时间:2017-06-02 12:42:24      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:pts   sse   set   log   point   编辑   bsp   val   duration   

var centerBPoints=[BPoint1,BPoint2,BPoint3,...];


                    var driving = new BMap.DrivingRoute(editMap, {
                        renderOptions: {
                            map: editMap, autoViewport: false, enableDragging: true,
                        }
                    });
                    points = [];

                    //driving.search(centerBPoints[0], centerBPoints[centerBPoints.length - 1]);

                    var waypoints = [];

                    for (var i = 1; i < centerBPoints.length - 1; i++) {
                        waypoints.push(centerBPoints[i]);
                    }

                    driving.search(centerBPoints[0], centerBPoints[centerBPoints.length - 1], { waypoints: waypoints });

                    driving.setPolylinesSetCallback(function () {
                        points = [];
                        var plan = driving.getResults().getPlan(0);    //通过驾车实例,获得一系列点的数组

                        $("#ForecastDistance").val(plan.getDistance(true));
                        $("#ForecastDuration").val(plan.getDuration(true));

                        for (var i = 0; i < plan.getNumRoutes() ; i++) {
                            var route = plan.getRoute(i);
                            var pts = route.getPath();
                            for (var j = 0; j < pts.length; j++) {
                                points.push(pts[j]);
                            }
                        }
                    });

                    editMap.setViewport([centerBPoints[0], centerBPoints[centerBPoints.length - 1]]);

 

百度地图 驾车路线编辑粗浅实例

标签:pts   sse   set   log   point   编辑   bsp   val   duration   

原文地址:http://www.cnblogs.com/xuhongcai/p/6932642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!