Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the color of the polyline in DirectionsRenderer

i've integrated a map and i want to display the route directions between two locations. everything is working fine and the directions is displayed perfectly , but i want to change the color of the Polyline direction ,i've tried this code like the documentation says :

//polyline options
    var pOptions = {
            map: map,
            strokeColor: "#2249a3",
            strokeOpacity: 0.9 ,
            strokeWeight: 12,
            z-index: 99
    };
    logJava(polylineOptions);

    //directionsRenderer options
    var mDirectionsRendererOptions = {
            map: map,
            suppressMarkers: true,
            suppressInfoWindows: true,
            polylineOptions: pOptions
    };

    logJava(mDirectionsRendererOptions);

    directionsDisplay = new google.maps.DirectionsRenderer(mDirectionsRendererOptions);

but when i add this code , it stops the map , and it displays nothing, when i comment it , everything is working fine .

what is wrong with this code, and how to change the color of the polyline with google maps javascript api v3 ?

Thanks in advance,

like image 896
Houcine Avatar asked Feb 16 '12 12:02

Houcine


2 Answers

At global declarations

var polylineOptionsActual = new google.maps.Polyline({
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 10
    });

At initialise

function initialize() {
   directionsDisplay = new google.maps.DirectionsRenderer({polylineOptions: polylineOptionsActual});    
like image 105
david strachan Avatar answered Sep 19 '22 20:09

david strachan


In answer marked as resolved I see that object Polyline used for polylineOptions. In my case I use the next code

new google.maps.DirectionsRenderer({ suppressMarkers: true, polylineOptions: { strokeColor: '#5cb85c' } });

The difference is that I assign polylineOptions, not Polyline object. Not sure it could be helpful, but decided to add these answer.

like image 40
Yara Avatar answered Sep 18 '22 20:09

Yara