android - 指定航路点时,Direction API 仅返回一条路线

标签 android json google-maps google-directions-api

我正在使用 Direction API 来显示源和目的地之间的路线。我像这样形成了 URL

https://maps.googleapis.com/maps/api/directions/json?origin=11.030342,77.038737&destination=11.0254792,76.968749&mode=driving&alternatives=true

它提供了“多条路线”,如下所示

`{"routes" : 
[
{  }
{  }
{  }
]}`

但是当我在 URL 中添加路径点时

https://maps.googleapis.com/maps/api/directions/json?origin=11.030342,77.038737&destination=11.0254792,76.968749&mode=driving&alternatives=true&waypoints=11.037647,77.037447

它给出了“单一路线”,如下所示

`{
 "routes" : 
 [{ 
 "legs" : [  {  }, {  }  ]
 }]
 }`

我指定了靠近起始位置的航路点,但仍然只获得单一路线。

我的 URL 或其方向 API 性质是否有任何错误?

有人遇到过这个问题吗?

最佳答案

根据这个article

Generally, only one entry in the routes array is returned for directions lookups, though the Directions service may return several routes if you pass alternatives=true.

因此,如果您添加 alternatives=true,并不能保证会获得一些替代路线

关于android - 指定航路点时,Direction API 仅返回一条路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47748874/

相关文章:

java - 通过 Maven 构建排除一些类

ruby-on-rails - 使用 Ruby on Rails 在 JSON 提要中呈现动态变量

android - 放大时显示相同的图 block 而不是从服务器获取它们

iphone - 如何在iphone应用程序中获取经纬度的地址

java.lang.RuntimeException : Unable to start activity: com. google.android.apps.messaging.ui.conversationlist.ShareIntentActivity - 找不到资源

android - 广播延迟

java - 哪种方法更快 ob.setText (""+int) 或 ob.setText(String.valueOf(int);

javascript - Blockly 的自定义语言生成器

PHP 到 JSON 编码数据不起作用

javascript - 隐藏的谷歌地图在打开时未加载到 fancybox 中