AI 地图
产品服务
解决方案
文档与支持
定价
更新时间: 2026/07/27 10:37
您当前查看的是 JSAPI GL 历史版本文档。该版本仅用于维护现有项目,不建议用于新项目开发。新项目请使用 JSAPI 4.0,如需升级现有项目,请参考升级指南
You are viewing the legacy JSAPI GL documentation. This version is maintained for existing projects only and is not recommended for new development. For new projects, use the JSAPI 4.0 documentation. If you are upgrading an existing project, please refer to the Migration Guide.
出行路线规划
简介

百度地图JavaScript API GL提供了驾车、公交、步行三种出行方式的路线规划功能。开发者在使用线路规划的接口时,可以使用我们提供的默认展示效果。也可以通过监听事件回调,使用检索数据完成自己的需求。

驾车路线规划

基础驾车路线规划服务示例:

var map = new BMapGL.Map('container');
map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
var p1 = new BMapGL.Point(116.301934, 39.977552);
var p2 = new BMapGL.Point(116.508328, 39.919141);
var driving = new BMapGL.DrivingRoute(map, { renderOptions: { map: map, autoViewport: true } });
driving.search(p1, p2);
公交路线规划

BMapGL.TransitRoute类提供公交线路规划服务。
使用服务示例:

var map = new BMapGL.Map('container');
map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 12);
var output = '从上地到西单坐公交需要:';
var transit = new BMapGL.TransitRoute(map, {
renderOptions: { map: map },
onSearchComplete: function (results) {
if (transit.getStatus() != BMAP_STATUS_SUCCESS) {
return;
}
var plan = results.getPlan(0);
output += '总时长:' + plan.getDuration(true); //获取时间
output += '总路程:' + plan.getDistance(true); //获取距离
$('#result').css('display', 'block');
$('#result').html(output);
},
});
var start = new BMapGL.Point(116.404844, 39.911836);
var end = new BMapGL.Point(116.308102, 40.056057);
transit.search(start, end);
步行路线规划

BMapGL.WalkingRoute提供步行线路规划服务。基本用法和驾车线路规划类似。
使用服务示例:

var map = new BMapGL.Map('allmap');
map.enableScrollWheelZoom();
map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
var walking = new BMapGL.WalkingRoute(map, { renderOptions: { map: map, autoViewport: true } });
walking.search('西单', '慈云寺');

上一篇

正/逆地址解析

下一篇

定位
本篇文章对您是否有帮助?