truckRouteSearchPage static method
最多支持6个途经点,8个一页
Implementation
static Future<void> truckRouteSearchPage({
required List<LatLng> wayPoints,
int? drivingMode,
TruckInfo? truckInfo,
int? showFields,//ShowFields.
RouteResultBack? back,
}) async {
if(wayPoints.length<2) return;
int pageLimit = 7; // 最大6个途经点即8个点,预留上一个连接点,正好每页7个
//int totalPage = wayPoints.length % pageLimit;//总页数
//需要采集的数据,分页只返回一條綫路
List<String> polylineList = [];
num distance = 0;
num duration = 0;
//开始分页采集
nextPage(page,limit) async {
List<LatLng> pagePoints = paging<LatLng>(wayPoints, page, pageLimit);
if(pagePoints.isEmpty){
if(back!=null) back(1000,RouteResult(paths: [Path(polyline:polylineList.join(";"),distance: distance,duration: duration)]));
return;
}
if(page>1) pagePoints.insert(0,pagingLast<LatLng>(wayPoints, page-1, pageLimit));//加入上一页的最后一个点,插在首位
await truckRouteSearch(wayPoints:pagePoints,drivingMode:drivingMode,showFields:showFields,truckInfo:truckInfo, back:(int? code, RouteResult data){
if(code != 1000) {
if(back!=null) back(code,data);//只要有一页报错,线路中断,就不要继续了
return;
}
if(data.paths==null || data.paths!.isEmpty) {
nextPage(page+1, pageLimit);
return;
}
List<String>? pointStr = data.paths?[0].polyline?.split(";");
if(pointStr!=null) polylineList.addAll(pointStr);
duration += data.paths?[0].duration??0;
distance += data.paths?[0].distance??0;
nextPage(page+1, pageLimit);
});
}
nextPage(1,pageLimit);
}