Step
此类表示驾车、步行或骑行路线中的一个关键点。它没有构造函数,通过Route.getStep()方法获得。
方法
| 方法 | 返回值 | 描述 |
|---|---|---|
getPosition() | Point | 返回关键点地理坐标 |
getIndex() | Number | 返回本关键点在路线中的位置索引 |
getDescription(includeHtml: Boolean) | String | 返回关键点描述文本,默认包含HTML标签。当includeHtml为false时,描述文本不包含HTML标签。不支持驾车路线规划 |
getDistance(format: Boolean) | String | Number | 返回到下一个关键点的距离,当format为false时仅返回数值(单位为米) |
示例
ts
// 创建路线规划实例(以步行路线为例)
const walkingRoute = new BMapGL.WalkingRoute(map, {
onSearchComplete: (results: BMapGL.WalkingRouteResult) => {
const plan = results.getPlan(0);
const route = plan.getRoute(0);
// 获取第一个关键点
const step = route.getStep(0);
// 获取关键点坐标
const position = step.getPosition();
// 获取关键点在路线中的索引
const index = step.getIndex();
// 获取关键点描述(包含HTML标签)
const description = step.getDescription(true);
// 获取关键点描述(不包含HTML标签)
const plainDescription = step.getDescription(false);
// 获取到下一个关键点的距离(带单位)
const distance = step.getDistance(true); // 例如:"100米"
// 获取到下一个关键点的距离(仅数值)
const distanceValue = step.getDistance(false); // 例如:100
}
});