出行路线规划
9.1 驾车与步行
RouteSearch routes = new RouteSearch(context);
routes.setRouteSearchListener(new RouteSearch.OnRouteSearchListener() {
public void onDriveRouteSearched(DriveRouteResult result, int code) {
if (code == SdkException.SUCCESS) report(result.getPaths());
else report(routes.getLastError());
}
public void onWalkRouteSearched(WalkRouteResult result, int code) {
if (code == SdkException.SUCCESS) report(result.getPaths());
else report(routes.getLastError());
}
});
RouteSearch.FromAndTo endpoints = new RouteSearch.FromAndTo(
new LatLonPoint(21.67623,100.02228), new LatLonPoint(21.68,100.03));
routes.calculateDriveRouteAsyn(new RouteSearch.DriveRouteQuery(
endpoints, RouteSearch.DRIVING_TIME));
// 步行另行调用:routes.calculateWalkRouteAsyn(new RouteSearch.WalkRouteQuery(endpoints));
| 查询参数 | 值 | 说明 |
|---|---|---|
| 驾车策略 | DRIVING_TIME=0、DRIVING_DISTANCE=1 | 时间优先、距离优先;不能透传其他高德枚举 |
| passedByPoints | 最多 16 点 | 驾车途经点 |
| avoidpolygons | 最多 32 个,每个 3–16 点 | 驾车避让区域 |
| avoidRoad | 最多 200 字符 | 避让道路名称;指定时优先于区域 |
| 步行策略 | WALK_DEFAULT=0 | 当前步行默认策略 |
高级驾车参数使用五参数 DriveRouteQuery(endpoints, mode, passedByPoints, avoidpolygons, avoidRoad)。服务端必须支持相应规划能力;本次 SDK 发布没有自动升级所有客户后台。若服务返回不支持,不能静默退化为忽略约束。
9.2 结果模型
DriveRouteResult.getPaths() / WalkRouteResult.getPaths() 返回路径;路径提供距离、耗时、polyline、steps。步骤包含道路名称、分段几何、距离及服务返回的指令/动作/耗时等。缺少可选字段时不得拼造导航指令。路线预览不能直接视为真实导航会话;导航应使用下一章控制器。