概述

     腾讯地图Direction API,提供多种交通方式的路线计算能力,包括:
     1. 驾车(driving):基于驾车路线规划;
     2. 步行(walking):基于步行路线规划。
     3. 骑行(bicycling):基于自行车的骑行路线;
     5. 公交(transit):支持公共汽车、地铁等多种公共交通工具的换乘方案计算;

     本服务通过请求URL参数设置路线查询条件,返回JSON结构化信息,在地图中显示路线需要结合地图API或SDK实现相应功能。


1)驾车(driving)路线规划

        该请求为GET请求

https://apis.map.qq.com/ws/direction/v1/driving?key=API_KEY&from=40.7480,-73.9862&to=40.7561,-73.9833

    参数说明

参数 必填 说明 示例
key 是 开发key key=OB4BZ-D4W3U-XXXXX
from 是 起点坐标:
lat<纬度>,lng<经度>
from=40.7480,-73.9862
to 是 终点坐标,格式:
lat<纬度>,lng<经度>
to=40.7561,-73.9833
waypoints 否 途经点,最多支持15个,
格式:lat1,lng1;lat2,lng2;…
waypoints=40.7504,-73.9873;40.7535,-73.986
policy 否 路线规划条件
(此参数仅在非日本地区有效)
LEAST_TIME:最快
REAL_TRAFFIC:实时交通
language 否 返回结果的语言:
cn [默认]中文
local 当地语言
支持的语言列表详见附录
language=en
callback 否 回调函数 callback=cb
output 否 返回值类型:json、jsonp output=json

返回值说明

参数 类型 必有 说明
status number 是 状态码,0为正常
message string 是 状态说明
result object 是 搜索结果
routes array 是 路线方案
mode string 是 方案交通方式,固定值:“DRIVING”
distance number 是 方案总距离,单位:米
duration number 是 方案估算时间(结合路况),单位:分钟
direction string 是 方案整体方向
polyline array 是 方案路线坐标点串(该点串经过压缩,解压请参考:polyline 坐标解压
waypoints array 否 途经点,顺序与输入waypoints一致 (输入waypoints时才会有此结点返回)
location object 否 途经点坐标
lat number 否 纬度
lng number 否 经度
polyline_idx number 否 该途经点在polyline中的索引位置(数组下标位置)
steps array 是 路线步骤
instruction string 是 阶段路线描述
polyline_idx array 是 阶段路线坐标点串在方案路线坐标点串的位置
road_name string 否 阶段路线路名
dir_desc string 否 阶段路线方向
distance number 是 阶段路线距离,单位:米
act_desc string 否 阶段路线末尾动作:如:左转调头

示例:

{
  "status": 0,
  "message": "query ok",
  "result": {
    "routes": [
      {
        "mode": "DRIVING",
        "distance": 1480,
        "duration": 5.77,
        "polyline": [
          40.7481923,
          -73.9860613,
          839,
          -1977,
        ],
        "steps": [
          {
            "instruction": "沿着 W 33rd St 朝 W 32nd St 行驶, 直行 192 米",
            "polyline_idx": [
              0,
              3
            ],
            "road_name": "W 33rd St",
            "distance": 192,
            "duration": 0.63,
            "act_desc": "depart"
          },
          //....中间省略
          {
            "instruction": "右转驶入 6th Ave, 直行 241 米",
            "polyline_idx": [
              8,
              19
            ],
            "road_name": "6th Ave",
            "distance": 241,
            "duration": 1.2,
            "act_desc": "rightTurn"
          },
          {
            "instruction": "继续沿 6th Ave 行驶, 直行 796 米",
            "polyline_idx": [
              18,
              55
            ],
            "road_name": "6th Ave",
            "distance": 796,
            "duration": 3.13,
            "act_desc": "continue"
          },
          {
            "instruction": "抵达 6th Ave 。目的地位于左侧",
            "polyline_idx": [
              54,
              55
            ],
            "road_name": "",
            "distance": 0,
            "duration": 0,
            "act_desc": "arrive"
          }
]
}
]
}
}



2)步行(walking)路线规划

请求URL示例:

https://apis.map.qq.com/ws/direction/v1/walking?key=API_KEY&from=40.7480,-73.9862&to=40.7561,-73.9833

参数说明:

参数 必填 说明 示例
key 是 开发key key=OB4BZ-D4W3U-XXXXX
from 是 起点位置坐标
格式:纬度在前,经度在后,半角逗号分隔。
from=39.915285,116.403857
to 是 终点位置坐标,格式:lat,lng
注:距离过长或过短会算路失败,最短距离不小于10米,最长距离不超过300公里
to=39.915285,116.803857
language 否 返回结果的语言:
cn [默认]中文
local 当地语言
支持的语言列表详见附录
language=en
callback 否 回调函数 callback=cb
output 否 返回值类型:json、jsonp output=json

响应结果

参数 类型 必有 说明
status number 是 状态码,0为正常,其它为异常
message string 是 状态说明
result object 是 搜索结果
routes array 是 路线方案
mode string 是 方案交通方式,固定值:“WALKING”
distance number 是 方案整体距离,单位:米
duration number 是 方案估算时间,单位:分钟
polyline array 是 方案路线坐标点串(该点串经过压缩,解压请参考:polyline 坐标解压)
steps array 是 路线步骤
instruction string 是 阶段路线描述
polyline_idx array 是 阶段路线坐标点串在方案路线坐标点串的位置
road_name string 否 阶段路线路名
dir_desc string 否 阶段路线方向
distance number 是 阶段路线距离,单位:米
act_desc string 否 阶段路线末尾动作

响应结果示例

{
    "status": 0,
    "message": "Success",
    "request_id": "here_e3e4835148e14b1991e75c0f0629f841",
    "result": {
        "routes": [
            {
                "mode": "WALKING",
                "distance": 4672,
                "duration": 78.82,
                "polyline": [
                    -23.522211,
                    -46.857983,
                    -109,
                    173,
                    -140,
                    200,

                ],
                "steps": [
                    {
                        "instruction": "Head southeast on Rua Arthur Montovanelli. Go for 172 m.",
                        "polyline_idx": [
                            0,
                            9
                        ],
                        "road_name": "Rua Arthur Montovanelli",
                        "duration": 0,
                        "distance": 172,
                        "act_desc": "depart"
                    },
                  //中间步骤省略
                    {
                        "instruction": "Turn left onto Avenida Doutor Dib Sauaia Neto. Go for 899 m.",
                        "polyline_idx": [
                            188,
                            213
                        ],
                        "road_name": "Avenida Doutor Dib Sauaia Neto",
                        "duration": 0,
                        "distance": 899,
                        "act_desc": "turn"
                    },
                    {
                        "instruction": "Arrive at Avenida Doutor Dib Sauaia Neto. Your destination is on the left.",
                        "polyline_idx": [
                            214,
                            215
                        ],
                        "road_name": "Avenida Doutor Dib Sauaia Neto",
                        "duration": 0,
                        "distance": 0,
                        "act_desc": "arrive"
                    }
                ]
            }
        ]
    }
}

3)骑行(bicycling)路线规划

        请求URL示例:

https://apis.map.qq.com/ws/direction/v1/bicycling?key=API_KEY&from=40.7480,-73.9862&to=40.7561,-73.9833

参数说明:

参数 必填 说明 示例
key 是 开发key key=OB4BZ-D4W3U-XXXXX
from 是 起点位置坐标
格式:纬度在前,经度在后,半角逗号分隔。
注:系统将吸附就近道路作为起点,最大20公里内若无道路,则会算路失败
from=-23.522301,-46.858051
to 是 终点位置坐标,格式:lat,lng
注:距离过长或过短会算路失败,最短距离不小于10米,最长距离不超过500公里
to=-23.522301,-46.858051
language 否 返回结果的语言:
cn [默认]中文
local 当地语言
支持的语言列表详见附录
language=en
callback 否 回调函数 callback=cb
output 否 返回值类型:json、jsonp output=json

响应结果

参数 类型 必有 说明
status number 是 状态码,0为正常,其它为异常,详细请参阅状态码说明
message string 是 状态说明
result object 是 搜索结果
routes array 是 路线方案
mode string 是 方案交通方式,固定值:“BICYCLING”
distance number 是 方案整体距离,单位:米
duration number 是 方案估算时间,单位:分钟
polyline array 是 方案路线坐标点串(该点串经过压缩,解压请参考:polyline 坐标解压)
steps array 是 路线步骤
instruction string 是 阶段路线描述
polyline_idx array 是 阶段路线坐标点串在方案路线坐标点串的位置
road_name string 否 阶段路线路名
dir_desc string 否 阶段路线方向
distance number 是 阶段路线距离,单位:米
act_desc string 否 阶段路线末尾动作

响应结果示例

{
    "status": 0,
    "message": "Success",
    "request_id": "here_14721e5efd2c468cbc430c3e64964e67",
    "result": {
        "routes": [
            {
                "mode": "BICYCLING",
                "distance": 4903,
                "duration": 23.22,
                "polyline": [
                    -23.522211,
                    -46.857983,
                    -109,
                    173,
                    -140,
                    200,
                ],
                "steps": [
                    {
                        "instruction": "Head southeast on Rua Arthur Montovanelli. Go for 95 m.",
                        "polyline_idx": [
                            0,
                            7
                        ],
                        "road_name": "Rua Arthur Montovanelli",
                        "duration": 0,
                        "distance": 95,
                        "act_desc": "depart"
                    },
                   //中间省略
                    {
                        "instruction": "Arrive at Avenida Doutor Dib Sauaia Neto. Your destination is on the left.",
                        "polyline_idx": [
                            242,
                            243
                        ],
                        "road_name": "Avenida Doutor Dib Sauaia Neto",
                        "duration": 0,
                        "distance": 0,
                        "act_desc": "arrive"
                    }
                ]
            }
        ]
    }
}

4)公交(transit)路线规划

基于公共汽车、地铁、等公共交通工具,计算起到终点的路线换乘方案。

请求URL

https://apis.map.qq.com/ws/direction/v1/transit?key=API_KEY&from=40.7480,-73.9862&to=40.7561,-73.9833

请求参数

参数 必填 说明 示例
from 是 起点坐标:
lat<纬度>,lng<经度>
form=40.7480,-73.9862
to 是 终点坐标,格式:
lat<纬度>,lng<经度>
to=40.7561,-73.9833
departure_time 否 出发时间,用于过滤掉非运营时段的线路,
格式为Unix时间戳,默认使用当前时间
departure_time=1509357129
language 否 返回结果的语言:
cn [默认]中文
local 当地语言
支持的语言列表详见附录
language=en
key 是 开发key key=fcebca0fceertga47dfabc30dssw9
callback 否 回调函数 callback=cb
output 否 返回值类型:json、jsonp output=json

响应结果

注:目前不支持韩国地区,返回结果 data 为空数组)

参数 类型 必有 说明
status number 是 状态码,0为正常,其它为异常
message string 是 状态说明
result object 是 计算结果
routes array 是 路线方案
distance number 是 方案整体距离,单位:米
duration number 是 方案估算时间,单位:分钟
bounds number 是 整体路线的外接矩形范围,可在地图显示时使用,
通过矩形西南+东北两个端点坐标定义而面,示例:
“39.901405,116.334023,39.940289,116.451720”
steps array 是 一条完整公交路线可能会包含多种公共交通工具,各交通工具的换乘由步行路线串联起来,形成这样的结构(即 steps数组的结构):
[步行 , 公交 , 步行 , 公交 , 步行(到终点)]
mode string 是 本段交通方式,取值:
WALKING:步行
TRANSIT:公共交通工具
不同的方式,返回不同的数据结构,须根据该参数值来判断以哪种结构进行解析,各类具体定义见下文
其它字段 - - 是 随mode不同有不同字段返回,见下文

响应结果 - 交通方式 - 步行

本段为步行方式的对象结构,对应result.steps[]数组下的子对象(“mode”:“WALKING”)

参数 类型 必有 说明
mode string 是 交通方式,固定值:“WALKING”,通过本参数判断数据结构类型
tags array 否 固定值为“SUPPLEMENT”表示该段为补充的步行起终点
distance number 是 本段step距离,单位:米
duration number 是 估算时间,单位:分钟
direction string 是 方案整体方向描述,如:“南”
polyline array 是 路线坐标点串,可用于在地图中绘制路线
(坐标串经过压缩,解压与使用,请参考下文)
steps array 否 分路段诱导信息,当该段有tags时,该字段不返回
routes array 是 路线方案
instruction string 是 诱导描述,如 “沿着 Mohrenstraße 向 东 步行, 直行 78 米“
polyline_idx array 是 本路段点串在polyline中的数组下标位置,格式:
“polyline_idx”:[起始下标位置,结束下标位置]
详细使用见下文《polyline_idx说明》
dir_desc string 否 本段主要方向描述
distance number 是 本段路线距离,单位:米
act_desc string 否 本段末尾动作:如:左转调头

响应结果 - 交通方式 - 公共交通(TRANSIT)

本段为公共交通方式的对象结构,对应result.steps[]数组下的子对象(“mode”:“TRANSIT”)

1. 交通工具 - 公共汽车(“vehicle”:“BUS”):

本段为公共交通的子对象,vehicle属性值为"BUS"

参数 类型 必有 说明
mode string 是 交通方式,固定值:“TRANSIT”,通过本参数判断数据结构类型
lines array 否 lines线路信息,因为起点到终点,可能存在多条线路可选,所以lines为数组,
而多条线路经过站点相同,所以数组第一会给出较完整信息,其它项则只返回路线名称等简要信息。
vehicle string 是 交通工具:公交车(BUS)
id string 是 线路唯一标识
title string 是 线路名称
station_count number 是 经停站数
price number 否 预估费用,单位:分,返回0时为缺少票价信息
distance number 是 路线距离,单位:米
duration number 是 路线估算时间,单位:分钟
polyline array 是 线路坐标点串,可用于在地图中绘制路线
(坐标串经过压缩,解压与使用,请参考下文)
destination object 是 公交终点站(用于指示方向)
title string 是 终点站名
start_time string 否 首班车时间
end_time string 否 末班车时间
geton object 是 上车站
id string 是 站点唯一标识
title string 是 站点名称
location object 是 站点经纬度坐标
lat number 是 纬度
lng number 是 经度
getoff object 是 下车站
id string 是 站点唯一标识
title string 是 站点名称
location object 是 站点经纬度坐标
lat number 是 纬度
lng number 是 经度
stations object array 是 经停站列表
id string 是 站点唯一标识
title string 是 站点名称
location object 是 站点经纬度坐标
lat number 是 纬度
lng number 是 经度

2. 交通工具 - 地铁(“vehicle”:“SUBWAY”):

本段为公共交通的子对象,vehicle属性值为"SUBWAY"

参数 类型 必有 说明
mode string 是 交通方式,固定值:“TRANSIT”,通过本参数判断数据结构类型
lines array 否 lines线路信息,因为起点到终点,可能存在多条线路可选,所以lines为数组,
而多条线路经过站点相同,所以数组第一会给出较完整信息,其它项则只返回路线名称等简要信息。
vehicle string 是 交通工具:地铁(subway)
id string 是 线路唯一标识
title string 是 线路名称
station_count number 是 经停站数
price number 否 预估费用,单位:分,返回0时为缺少票价信息
distance number 是 路线距离,单位:米
duration number 是 路线估算时间,单位:分钟
polyline array 是 线路坐标点串,可用于在地图中绘制路线
(坐标串经过压缩,解压与使用,请参考下文)
destination object 是 终点站,用于表明乘坐方向,环线线路为下一站
title string 是 终点站名
geton object 是 上车站
id string 是 站点唯一标识
title string 是 站点名称
location object 是 站点经纬度坐标
lat number 是 纬度
lng number 是 经度
getoff object 是 下车站
id string 是 站点唯一标识
title string 是 站点名称
location object 是 站点经纬度坐标
lat number 是 纬度
lng number 是 经度
stations object array 是 途经站列表
id string 是 站点唯一标识
title string 是 站点名称
location object 是 站点经纬度坐标
lat number 是 纬度
lng number 是 经度

示例:

{
    "status": 0,
    "message": "Success",
    "request_id": "here_7a2ddff7ca4a4db3a8052eb8940a15c1",
    "result": {
        "routes": [
            {
                "distance": 4874,
                "duration": 21,
                "price": 0,
                "bounds": "52.497734,13.361986,52.517423,13.396049",
                "steps": [
                    {
                        "mode": "WALKING",
                        "distance": 222,
                        "duration": 4,
                        "direction": "东北",
                        "polyline": [
                            52.497789,
                            13.361986,
                            141,
                            64,
                            490,
                            200,
                            820,
                            340,
                            490,
                            200
                        ],
                        "steps": [
                            {
                                "instruction": "沿着 Potsdamer Straße 向 北 步行, 直行 222 米",
                                "polyline_idx": [
                                    0,
                                    7
                                ],
                                "dir_desc": "东北",
                                "distance": 222,
                                "act_desc": ""
                            },
                            {
                                "instruction": "抵达 Potsdamer Straße 。目的地位于右侧",
                                "polyline_idx": [
                                    8,
                                    9
                                ],
                                "dir_desc": "",
                                "distance": 0,
                                "act_desc": ""
                            }
                        ]
                    },
                    //地铁段
                    {
                        "mode": "TRANSIT",
                        "lines": [
                            {
                                "vehicle": "subway",
                                "id": "R0-S1",
                                "title": "U12",
                                "station_count": 2,
                                "price": 0,
                                "destination": {
                                    "title": "Warschauer Straße"
                                },
                                "distance": 2005,
                                "duration": 5,
                                "polyline": [
                                    52.499688,
                                    13.362839,
                                    -52,
                                    271,
                                    -27,
                                    227,
                                    -8,
                                ],
                                "geton": {
                                    "id": "107634_610210",
                                    "title": "U Kurfürstenstr.",
                                    "location": {
                                        "lat": 52.49978,
                                        "lng": 13.362857
                                    }
                                },
                                "getoff": {
                                    "id": "107634_610028",
                                    "title": "U Hallesches Tor",
                                    "location": {
                                        "lat": 52.497772,
                                        "lng": 13.39176
                                    }
                                },
                                "stations": [
                                    {
                                        "id": "107634_609981",
                                        "title": "U Gleisdreieck",
                                        "location": {
                                            "lat": 52.499588,
                                            "lng": 13.374293
                                        }
                                    },
                                    {
                                        "id": "107634_610323",
                                        "title": "U Möckernbrücke",
                                        "location": {
                                            "lat": 52.498943,
                                            "lng": 13.383256
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    //步行段
                    {
                        "mode": "WALKING",
                        "distance": 503,
                        "duration": 8,
                        "direction": "东北",
                        "polyline": [
                            52.516974,
                            13.38888,
                            136,
                            1800,
                            140,
                            1950,
                            40,
                            490,
                            -80,
                            10,
                            
                        ],
                        "steps": [
                            {
                                "instruction": "沿着 Unter den Linden 向 东 步行, 直行 503 米",
                                "polyline_idx": [
                                    0,
                                    23
                                ],
                                "dir_desc": "东北",
                                "distance": 503,
                                "act_desc": ""
                            },
                            {
                                "instruction": "抵达 Unter den Linden",
                                "polyline_idx": [
                                    24,
                                    25
                                ],
                                "dir_desc": "",
                                "distance": 0,
                                "act_desc": ""
                            }
                        ]
                    }
                ]
            },
            {
                "distance": 3602,
                "duration": 32,
                "price": 0,
                "bounds": "52.497620,13.361960,52.517423,13.396049",
                "steps": [
                    {
                        "mode": "WALKING",
                        "distance": 36,
                        "duration": 1,
                        "direction": "东南",
                        "polyline": [
                            52.49773,
                            13.36196,
                            0,
                            0,
                            -50,
                            200,
                            -60,
                            292
                        ],
                        "steps": [
                            {
                                "instruction": "沿着 Bülowstraße 向 东 步行, 直行 36 米",
                                "polyline_idx": [
                                    0,
                                    5
                                ],
                                "dir_desc": "东南",
                                "distance": 36,
                                "act_desc": ""
                            },
                            {
                                "instruction": "抵达 Bülowstraße",
                                "polyline_idx": [
                                    6,
                                    7
                                ],
                                "dir_desc": "",
                                "distance": 0,
                                "act_desc": ""
                            }
                        ]
                    },
                    //公交段
                    {
                        "mode": "TRANSIT",
                        "lines": [
                            {
                                "vehicle": "bus",
                                "id": "R1-S1",
                                "title": "M85",
                                "station_count": 7,
                                "price": 0,
                                "destination": {
                                    "title": "U Stadtmitte"
                                },
                                "distance": 2524,
                                "duration": 14,
                                "polyline": [
                                    52.497733,
                                    13.362085,
                                    70,
                                    20,
                                    260,
                                    117,
                                    117,
                                   
                                ],
                                "geton": {
                                    "id": "107634_609872",
                                    "title": "U Bülowstr.",
                                    "location": {
                                        "lat": 52.497627,
                                        "lng": 13.362456
                                    }
                                },
                                "getoff": {
                                    "id": "107634_610652",
                                    "title": "U Stadtmitte",
                                    "location": {
                                        "lat": 52.511494,
                                        "lng": 13.389719
                                    }
                                },
                                "stations": [
                                    {
                                        "id": "107634_610210",
                                        "title": "U Kurfürstenstr.",
                                        "location": {
                                            "lat": 52.49978,
                                            "lng": 13.362857
                                        }
                                    },
                                    //后面省略
                                    }
                                ]
                            }
                        ]
                    }


polyline 坐标解压

polyline为数值型一维数组,格式为:
[坐标1纬度 , 坐标1经度 , 坐标2纬度 , 坐标2经度 , 坐标3纬度 , 坐标3经度…],
第一个坐标为原始未被压缩过的,之后的使用前向差分进行压缩,解压方法如下:

var coors=[50.243916,127.496637,-345,-1828,19867,-26154];
for (var i = 2; i < coors.length ; i++)
{coors[i] = coors[i-2] + coors[i]/1000000}

polyline_idx说明

下图为polyline的数组结构,路线全程的坐标点串都在polyline中, "polyline_idx"表达的是路段点串在polyline中的数组下标位置(而非坐标个数位置)的开始到结束序号,举个例子,假设某路段(steps)在polyline中是第4到第6个坐标,则polyline_idx为 “polyline_idx”:[6,11]



注意事项

        起点、终点、途经点若不在道路上,会自动吸附到附近的道路上:

|

本页内容