Hallo,
you have to iterate through the legs of the route and the steps of the legs to generate a polyline.
As an example look at:
http://www.gas-tankstellen.de/routeCngLpgFinder/routeCngLpgFinder-en.htmlIn the source code look at routeMain.js and navigate to initialize() and find the line, where onClickRoute(); is called. Follow the calls of getRoute, directionsService.route(...), createRoutePoly(route);
The iteration is done in createRoutePoly(route);
/**
*Creates the polyline of a route.
*@param route the route object
*@return {polyline,route distance in kms}
*/
function createRoutePoly(route){
var legs=route.legs;
var path=new Array();
var steps, leg;
var polylineLength=0.0;
for(var i=0; i< legs.length; i++){
leg=legs[i];
polylineLength+=leg.distance.value;
steps=leg.steps;
for (var s=0; s<steps.length; s++){
path=path.concat(steps[s].path);
}
}
var polyOpts={
map:map,
path:path,
strokeColor:"#ff0000",
strokeOpacity:0.9,
strokeWeight:2
};
var polyline=new google.maps.Polyline(polyOpts);
return {
polyline:polyline,
polylineLength:polylineLength/1000.0
};
}
Regards
BO