DirectionsServiceを使用するときに、directionsRendererにmouseoverイベントリスナーを追加するにはどうすればよいですか?DirectionsRendererにmouseoverイベントを追加するGoogle Maps API v3
リスナーを直線に追加する方法はわかっていますが、DirectionsRendererでオブジェクトが見つからないようです。
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;
}
をしかし、これにはない:
たとえば、この作品
代わりdirectionsPath私が試した結果の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;
}
、result.routes [0]、およびいくつかの他。
どのようなオブジェクトを使用する必要がありますか?
私はこれを答えとしてマークしていますが、私はドラッグイベントを使用するので、それはまだ完全ではありません。 –