Google Maps API how to add current traffic conditions on routes -


any great thank in advance.

i have code display main route , alternative route, i'm trying display traffic conditions of route example:

if go maps , directions show red or yellow lines on route. determined traffic conditions. there way show traffic conditions on map?

i know theirs traffic condition service, shows traffic of area. need traffic on route.

my code

var lontlatobejct = sharedproperties.getstring();                    var myoptions = {             zoom: 10,             center: new google.maps.latlng(lontlatobejct.strloclatitude, lontlatobejct.strloclongitude),             maptypeid: google.maps.maptypeid.roadmap,             maptypecontrol: false         };         var mapobject = new google.maps.map(document.getelementbyid("divmap"), myoptions);          var mapcanvas = document.getelementbyid('divmap');         var start = document.getelementbyid('txtstartingaddress').value.tostring();         var end = document.getelementbyid('txtendingaddress').value.tostring();         var request = {             origin: start,             destination: end,             provideroutealternatives: true,             travelmode: google.maps.directionstravelmode.driving,             unitsystem: google.maps.unitsystem.metric         };           directionsdisplay.setmap(mapobject);         directionsdisplay.setpanel(document.getelementbyid("divdirectionspanel"));          directionsservice.route(             request,             function (response, status) {                 if (status == google.maps.directionsstatus.ok) {                     (var = 0, len = response.routes.length; < len; i++) {                                                switch(i){                             case 0:                                 new google.maps.directionsrenderer({                                     map: mapobject,                                     directions: response,                                     routeindex: i,                                     draggable: true                                 });                                 break;                                                           default:                                 new google.maps.directionsrenderer({                                     map: mapobject,                                     directions: response,                                     routeindex: i,                                     draggable: true,                                     polylineoptions: { strokecolor: '#666666', strokeweight: 6, strokeopacity: .7 },                                     suppressmarkers: true,                                                               });                         }                                            }                     directionsdisplay.setdirections(response);                  } else {                  }             }         ); 

your option google.maps.trafficlayer

var trafficlayer;  ...  if (!trafficlayer || !trafficlayer.setmap)    trafficlayer = new google.maps.trafficlayer();  if (status == google.maps.directionsstatus.ok) {   trafficlayer.setmap(mapobject); ... } else {   trafficlayer.setmap(null); } 

Popular posts from this blog