Receive events from a polyline or marker from a DirectionsRenderer

I am using the DirectionsService and route method to create a DirectionsResult. I also use the DirectionsRenderer object to display the results, because it is very easy to use. I have no problem detecting events_changed events, but I would like to know if it is possible to get events from the polyline representing the route, or even events from markers (small circles) generated after dragging the polyline.

When using google maps (maps.google.com, "Get Directions"), you can drag the polyline, right-click on it (or markers), this will lead to a menu display. Therefore, I suppose there is a way to catch events from the DirectionsRenderer (suppose Google uses this object in this case).

If someone got an idea

+3
source share
1 answer

I am also looking for the answer to your question. Until then, I will try to figure it out myself, and I will send it back if I find something useful.

: JavaScript , DirectionsResult , , , . Draggable Directions, directionDisplay.directions, direction_changed . sf, , , , null. location, wa () ya ().

, , . , script;

var markers = [];  

direction_changed

google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {  
    computeTotalDistance(directionsDisplay.directions);  
});

:

google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {  
    computeTotalDistance(directionsDisplay.directions);  
    displayWaypoints(directionsDisplay.directions);  
});

function displayWaypoints(result) {  
    for (var i = 0; i < markers.length; ++i) {  
        markers[i].setMap(null);  
    }  
    markers = [];  
    if (result.sf.waypoints) {  
            for (var i = 0; i < result.sf.waypoints.length; ++i) {  
                    var latitude = result.sf.waypoints[i].location.wa;  
                    var longitude = result.sf.waypoints[i].location.ya;    
                    markers.push(new google.maps.Marker({  
                            position: new google.maps.LatLng(latitude, longitude),  
                            map: map  
                    }));  
            }  
    }  
}  

DirectionsRenderer.

var rendererOptions = {  
    draggable: true  
};  

var rendererOptions = {  
    draggable: true,  
    suppressMarkers: true  
};  

sf. , Google API . API , , .

, , .

,

+3

All Articles