1. 程式人生 > >百度地圖 駕車路線編輯粗淺實例

百度地圖 駕車路線編輯粗淺實例

edr call sset driving route drag getpath pre fun

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]]);

百度地圖 駕車路線編輯粗淺實例