如何获取更改在Google渲染容器中显示的选定路线的事件? [英] How to get the event on changing the selected route displaying in a google render container?
本文介绍了如何获取更改在Google渲染容器中显示的选定路线的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是代码:
var map = new google.maps.Map(document.getElementById(map_canvas) ,$ scope.map_options);
var dirService = new google.maps.DirectionsService();
var dirRenderer = new google.maps.DirectionsRenderer()
var dirContainer = document.getElementById('dir-container');
$ b var showDirections = function(dirResult,dirStatus){
if(dirStatus!= google.maps.DirectionsStatus.OK){
alert('Directions failed: '+ dirStatus);
return;
}
//显示路线
dirRenderer.setMap(map);
dirRenderer.setDirections(dirResult);
dirRenderer.setPanel(dirContainer);
};
dirService.route({origin:'158 cours tolstoi,villeurbanne',
destination:'8 coursandréphilip,villeurbanne',
travelMode:google.maps.DirectionsTravelMode。 DRIVING,
provideRouteAlternatives:true}
,showDirections);
我想要捕获在dirContainer中显示的路线之间选择另一条路线的事件。 p>
替代品路线显示在dirContainer中,因为provideRouteAlternatives:true。
事件
google.maps.event.addListener(dirRenderer,'directions_changed',
function(){
alert('a') ;
});
在您更改替代路线时未触发。
提前致谢。
解决方案
以下是活动:
google.maps.event.addListener(dirRenderer,'routeindex_changed',
function(){
alert(dirRenderer.getRouteIndex());
});
Here is the code :
var map = new google.maps.Map(document.getElementById("map_canvas"), $scope.map_options);
var dirService= new google.maps.DirectionsService();
var dirRenderer= new google.maps.DirectionsRenderer()
var dirContainer=document.getElementById('dir-container');
var showDirections = function(dirResult, dirStatus) {
if (dirStatus != google.maps.DirectionsStatus.OK) {
alert('Directions failed: ' + dirStatus);
return;
}
// Show directions
dirRenderer.setMap(map);
dirRenderer.setDirections(dirResult);
dirRenderer.setPanel(dirContainer);
};
dirService.route( {origin: '158 cours tolstoi, villeurbanne',
destination: '8 cours andré philip, villeurbanne',
travelMode: google.maps.DirectionsTravelMode.DRIVING,
provideRouteAlternatives: true }
, showDirections);
I would like to catch the event of selecting another route between the route displaying in the dirContainer.
The alternatives route are displaying in the dirContainer and because provideRouteAlternatives: true.
The event
google.maps.event.addListener(dirRenderer, 'directions_changed',
function() {
alert('a');
});
is not fired when you change the alternative route.
In advance thanks.
解决方案
Here is the event :
google.maps.event.addListener(dirRenderer, 'routeindex_changed',
function() {
alert(dirRenderer.getRouteIndex());
});
这篇关于如何获取更改在Google渲染容器中显示的选定路线的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文