您可以通过以下两种方式之一设置沿途停靠点(例如接送点):
- 添加中间航点:这是默认选项。在
intermediates数组中,在出发地和目的地之间添加一个中间航点。路线引擎会将航点贴靠到最近的可导航道路,并将路线划分为由该停靠点连接的RouteLeg个路段。 - 指定 vehicleStopover:如果您希望路线引擎执行额外分析,以避开不适合停车的路段(例如高速公路、隧道或立交桥),请在航点上设置
vehicleStopover: true。
添加中间航点
如需设置沿途经停点,请在请求中向 intermediates 数组添加中间航点。
添加中间航点会产生以下影响:
- 路线分为
RouteLeg个路段:每个路段连接一个经停点和下一个经停点。 - 坐标会吸附到道路:路线规划引擎会将您的纬度和经度坐标(可能位于屋顶或院子中)吸附到最近的可导航路段。
对于许多地面街道,吸附到最近的道路可提供实用的停靠位置。不过,吸附功能无法确定该路段是否适合靠边停车,例如当最近的道路是高速公路或隧道时。
示例:添加中间航点
以下示例演示了如何通过在 computeRoutes POST 请求中添加中间航点来设置沿路线的停靠点:
curl -X POST -d '{ "origin":{ "location":{ "latLng":{ "latitude": 37.419734, "longitude": -122.0827784 } } }, "destination":{ "location":{ "latLng":{ "latitude": 37.417670, "longitude": -122.079595 } } }, "intermediates": [ { "location":{ "latLng":{ "latitude": 37.419734, "longitude": -122.0807784 } } } ], "travelMode": "DRIVE" }' \ -H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \ -H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.legs' \ 'https://routes.googleapis.com/directions/v2:computeRoutes'
如需详细了解中间航点和路线路段,请参阅设置中间航点。
指定 vehicleStopover 以确定是否适合接送
虽然标准中间航点会吸附到最近的道路,但该道路并不总是适合车辆停靠。如果您希望路线引擎执行额外分析,以评估道路是否适合接送,请在航点上设置 vehicleStopover: true。
设置 vehicleStopover: true 后,路线规划引擎会评估候选路段,并尝试避开不适合停车的道路,例如高速公路、隧道和立交桥。
例如,假设某个位置有一条地面道路直接穿过隧道内的公路: * 标准中间航点:如果下方的公路或隧道在几何上更接近您的坐标,则会吸附到该公路或隧道。 * 车辆中途停靠:执行额外分析以绕过高速公路和隧道,将停靠点吸附到适合靠边停车的地面道路。
示例:在航点上指定 vehicleStopover
以下示例演示了如何在完整的 POST 请求中为中间航点设置 vehicleStopover: true:
curl -X POST -d '{ "origin":{ "location":{ "latLng":{ "latitude": 37.419734, "longitude": -122.0827784 } } }, "destination":{ "location":{ "latLng":{ "latitude": 37.417670, "longitude": -122.079595 } } }, "intermediates": [ { "location":{ "latLng":{ "latitude": 37.419734, "longitude": -122.0807784 } }, "vehicleStopover": true } ], "travelMode": "DRIVE" }' \ -H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \ -H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.legs' \ 'https://routes.googleapis.com/directions/v2:computeRoutes'
如需详细了解航点类型和选项,请参阅航点类型和选项。