Tak też mam aktualnie. Napisałem sobie taką funkcję(sorry za czytelność ale funkcja jest po kompresji a wersję developerską gdzieś mi wcieło)
function calcRoute() {
if (trasa != null)
trasa.setMap(null);
var e = document.getElementById("autocomplete").value;
var t = document.getElementById("autocomplete_to").value;
var n = [];
var r = document.getElementById("additional_places").value;
if (r.trim() != '') {
var i = r.toString().split(";");
for (var s = 0; s < i.length; s++) {
if (i[s] !== "") {
n.push({location: i[s], stopover: true})
}
}
}
var o = {origin: e, destination: t, waypoints: n, optimizeWaypoints: false, provideRouteAlternatives: true, travelMode: google.maps.TravelMode.DRIVING};
var u = new google.maps.DirectionsService;
u.route(o, function (e, t) {
if (t == google.maps.DirectionsStatus.OK) {
var r = document.getElementById("distance");
var i = document.getElementById("dist_inp");
for (var ind = 0, len = e.routes.length; ind < len; ind++) {
var n = e.routes[ind];
r.innerHTML = "";
var s = 0;
for (var o = 0; o < n.legs.length; o++) {
s += parseInt(n.legs[o].distance.value)
}
r.innerHTML = s / 1e3;
i.value = s / 1e3;
if (ind > 0) {
polylineOptions = {map: map, strokeColor: "#c7c3c7", strokeOpacity: .7, strokeWeight: 5, path: e.routes[ind].overview_path};
} else {
polylineOptions = {map: map, strokeColor: "#FF0000", strokeOpacity: .7, strokeWeight: 5, path: e.routes[ind].overview_path};
}
trasa = new google.maps.Polyline(polylineOptions);
map.fitBounds(e.routes[ind].bounds);
}
}
});
}
jeśli na koniec pętli for dodam sobie
google.maps.event.addDomListener(trasa, 'click', function () {
alert('lorem');
});
to alert działa ale wiadomo - tylko w przypadku ostatniej trasy
=======
ok mam
trasa.addListener("click", function () {
alert(this)
}.bind(ind));