工具:compute_routes
计算指定出发地和目的地之间的出行路线。支持的出行方式:DRIVE(默认)、WALK。
输入要求(严重):需要同时提供出发地和目的地。必须使用以下方法之一在相应字段中嵌套提供每个参数:
address:(字符串,例如 “巴黎埃菲尔铁塔”)。注意:输入的地址越精细或越具体,结果就越好。
lat_lng::(对象,{"latitude": number, "longitude": number})
place_id::(字符串,例如 'ChIJOwE_Id1w5EAR4Q27FkL6T_0') 注意:此 ID 可通过 search_places 工具获取。允许使用任何输入类型组合(例如,按地址指定出发地,按 lat_lng 指定目的地)。如果缺少出发地或目的地,您必须先询问用户以明确信息,然后再尝试调用该工具。
工具调用示例:{"origin":{"address":"Eiffel Tower"},"destination":{"place_id":"ChIJt_5xIthw5EARoJ71mGq7t74"},"travel_mode":"DRIVE"}
以下示例演示了如何使用 curl 调用 compute_routes MCP 工具。
| Curl 请求 |
|---|
curl --location 'https://mapstools.googleapis.com/mcp' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "compute_routes", "arguments": { // provide these details according to the tool's MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
输入架构
ComputeRoutesRequest。
ComputeRoutesRequest
| JSON 表示法 |
|---|
{ "origin": { object ( |
| 字段 | |
|---|---|
origin |
必需。起点途径点。 |
destination |
必需。目的地途经点。 |
travelMode |
可选。指定交通方式。 |
航点
| JSON 表示法 |
|---|
{ // Union field |
| 字段 | |
|---|---|
联合字段 location_type。表示位置的不同方式。location_type 只能是下列其中一项: |
|
latLng |
使用地理坐标指定的点。 |
placeId |
与途经点关联的地点 ID。 |
address |
人类可读的地址或 Plus Code。如需了解详情,请参阅 https://plus.codes。 |
LatLng
| JSON 表示法 |
|---|
{ "latitude": number, "longitude": number } |
| 字段 | |
|---|---|
latitude |
纬度(以度为单位)。它必须在 [-90.0, +90.0] 范围内。 |
longitude |
经度(以度为单位)。它必须在 [-180.0, +180.0] 范围内。 |
输出架构
ComputeRoutesResponse。
ComputeRoutesResponse
| JSON 表示法 |
|---|
{
"routes": [
{
object ( |
| 字段 | |
|---|---|
routes[] |
包含所请求的出发地和目的地之间的路线。目前仅返回一条路线。 |
路线
| JSON 表示法 |
|---|
{ "distanceMeters": integer, "duration": string } |
| 字段 | |
|---|---|
distanceMeters |
路线的行驶距离(以米为单位)。 |
duration |
导航相应路线所需的时间。 该时长以秒为单位,最多包含九个小数位,以“ |
时长
| JSON 表示法 |
|---|
{ "seconds": string, "nanos": integer } |
| 字段 | |
|---|---|
seconds |
时间段的带符号秒数。必须介于 -315,576,000,000 到 +315,576,000,000 之间(含边界值)。注意:这些界限是通过以下计算得出的:60 秒/分钟 * 60 分钟/小时 * 24 小时/天 * 365.25 天/年 * 10000 年 |
nanos |
时间跨度的有符号秒数小数部分(精确到纳秒)。小于 1 秒的时长用 0 |
工具注释
破坏性提示:❌ | 等幂性提示:❌ | 只读提示:✅ | 开放世界提示:❌