百度地图 驾车路线编辑粗浅实例
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]]);