无论我设置什么出发地和目的地,我总是得到一条路线

I'm always getting a single route no matter what origin and destination I set

我正在按照 docs 中的说明进行操作。我的 link 看起来像这样:

https://maps.googleapis.com/maps/api/directions/json?origin=lat,lng&destination=lat,lng&mode=walking&key=KEY

效果很好。然而,无论我设置的起点或终点是什么,我总是得到一个带有单一路线的 JSON 文件。请参阅以下屏幕截图:

https://ibb.co/x7K4B1c

这是正确的吗?有什么办法可以获得多条路线吗?

来自方向 API documentation

alternatives — If set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server. This is only available for requests without intermediate waypoints.

您需要设置备选方案以获取从起点到终点的一条或多条路线。

在您的情况下,您可以这样尝试并查看输出

https://maps.googleapis.com/maps/api/directions/json?origin=lat,lng&destination=lat,lng&mode=walking&key=KEY&alternatives=true