You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Routes API中获取waypoint_order途经点顺序数组?

如何让Google Routes API返回按顺序排列的途经点索引数组

要获取类似Directions API中waypoint_order的途经点排序结果,你需要对请求体做关键修改:

  • 添加routeModifiers配置,启用途经点优化功能

修改后的请求体示例

{
  "origin":{
      "location":{
        "latLng":{
          "latitude": -15.636545,
          "longitude": -47.633539
        }
      }
    },
  "destination":{
      "location":{
        "latLng":{
          "latitude": -15.630800,
          "longitude": -47.652165
        }
      }
    },
  "intermediates": [
    {
      "location":{
        "latLng":{
          "latitude": -15.636709,
          "longitude": -47.659976
        }
      }
    },
    {
      "location":{
        "latLng":{
          "latitude": -15.642289,
          "longitude": -47.658088
        }
      }
    }
  ],
  "travelMode": "DRIVE",
  "routeModifiers": {
    "waypointOptimization": true
  }
}

说明

启用waypointOptimization: true后,Google Routes API会自动计算途经点的最优访问顺序,在响应的routes[].optimizedIntermediateWaypointIndex字段中返回原始intermediates数组的索引列表,该数组作用完全等同于Directions API中的waypoint_order,可直接用于获取排序后的途经点序列。

内容的提问来源于stack exchange,提问作者Daniel Ribeiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 02:25:09