polylineOptions not working with DirectionsRenderer

576 views
Skip to first unread message

Akash

unread,
Sep 1, 2010, 5:48:05 AM9/1/10
to Google Maps JavaScript API v3
Hi,
Following code was not working for me
var polylineOptions = {
map: map,
strokeColor: color,
strokeOpacity: "#FF0000",
strokeWeight: 4
}

directionsDisplay = new
google.maps.DirectionsRenderer({ polylineOptions: polylineOptions });
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);

and I found following workaround. I hope it will help others.

Thanks,
-Akash


if (status == google.maps.DirectionsStatus.OK) {
var polylineOptions = new
google.maps.Polyline({ strokeColor: color, strokeWeight: 1 });

directionsDisplay = new
google.maps.DirectionsRenderer({ polylineOptions: polylineOptions });
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);

var legs = response.routes[0].legs;

for (var leg = 0; leg < legs.length; leg++) {
for (var step = 0; step < legs[leg].steps.length;
step++) {
if (legs[leg].steps[step].lat_lngs) {
var polylineOptions = {
map: map,
strokeColor: color,
strokeOpacity: 0.7,
strokeWeight: 4,
path: legs[leg].steps[step].lat_lngs
}
new google.maps.Polyline(polylineOptions);
}
}
}
Reply all
Reply to author
Forward
0 new messages