How can I add a mouseover event listener to directionRenderer when using a DirectionsService?
I know how to add a listener to a straight line, but cannot find the object in directionRenderer.
For example, this works:
function getStraightLine(coordinates) { if (progress.length == 0) progress = coordinates; else progress.push(coordinates[1]); updateDistance(); var line = new google.maps.Polyline({ path: coordinates, strokeColor: "#FF0000", strokeOpacity: .5, strokeWeight: 2, map: map }); google.maps.event.addListener(line, 'mouseover', function(){ alert("moused over straight line!"); }); return line; }
But this is not so:
function getDirectionsPath(coordinates) { var directionsPath = new google.maps.DirectionsRenderer(); directionsPath.setMap(map); var request = { origin: coordinates[0], destination: coordinates[1], travelMode: google.maps.TravelMode.WALKING }; directionsService.route(request, function (result, status) { if (status == google.maps.DirectionsStatus.OK) { var coordinates = result.routes[0].overview_path; if (progress.length == 0) progress = coordinates; else progress = progress.concat(coordinates); directionsPath.setDirections(result); google.maps.event.addListener(directionsPath, 'mouseover', function(){ alert("moused over straight line!"); }); } }); return directionsPath; }
Instead of Path directions, I tried the result, result.routes [0] and several others.
So which object should I use?
source share