获取选定的路线或路线索引

时间:2014-07-16 06:34:39

标签: javascript google-maps google-maps-api-3

我正在使用谷歌地图javascript api,并且有一些工作正常,包括航路点和显示,但我要求谷歌寻找其他路线(通常会返回3),方向面板会将它们显示为选择。

我无法在文档中找到任何可以让我知道用户选择的内容,是否有我可以回复的事件或内置的内容?

1 个答案:

答案 0 :(得分:1)

您可以通过DirectionsRenderer的方法getRouteIndex获得所选路线的索引。

检测routeIndex上的更改的可能事件是routeindex_changed

  google.maps.event.addListener(directionsRenderer,'routeindex_changed',function(){
     //current routeIndex
     console.log(this.getRouteIndex());  
     //current route
     console.log(this.getDirections().routes[this.getRouteIndex()]);   
  });
相关问题