pravin_kr


I have a requirement of plotting two routes on the map. Say from point A to B and then, from point B to C and display total distance and time. The problem is that when i try to plot the second route, the first route disappers. I am able to collect the itinary informations of both these routes, so plotting pushpins for both these routes is possible.Any idea how can i retain the first route driving lines on the map and able to call the getRoute method again for the second route.

I guess, when GetRoute method is called second time, it deletes previous routes from the map.





Re: multiple routes

Derek Chan


Unfortuantely VE4 doesn't support multiple routes on the same map. What goes on in the API is that a call is made to remove all routes on the map whenever map.GetRoute() is called.





Re: multiple routes

sathish_indian

Hi pravin,

I am having same requirement as you. Can you pls give an idea how you made the second route ie. from B to C after showing A to B.

I need to show only the distance between two routes A to B and A to C. I used a loop to pass the set of Latitude and longitude values to

map.GetRoute function. But i am getting only one route...

Pls tell tell how you pass both the values







Re: multiple routes

Harvester

What Derek was saying earlier is that with the V4 API of VE you cannot do this. As far as I can tell V5 (released in the last few weeks) doesn't offer this yet, either.

You could try capturing the SVG polyline and RouteIntinerary that results as you're looping through your point pairs, converting all the pixels in the polyline to latlongs and then rendering it as one large polyline with manually placed flags for the routesegment pins.

I think it could be done, and actually got a little ways towards completing it but was told to stop because my company will wait for MS to implement this in VE, rather than hack our own solution. VE support has informed me that the fall release of VE will most likely contain this feature. (Multiple destination routing)

Greg




Re: multiple routes

pravin_kr

Sathish..calculating the total distance from AtoB then B to C is fairly easy job. If the number of stop points are confined to just three, then you can use the below code the know to distance from A to C,

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Driving Direction</title>

<script language="javascript" type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>

<script language="javascript" type="text/javascript">

var map = null;

var map = null;

var totalDistance=0;

function GetMap()

{

map = new VEMap('myMap');

map.LoadMap();

map.GetRoute("Seattle", "Microsoft",VEDistanceUnit.Miles, VERouteType.Shortest, onGotRoute1);

}

function onGotRoute1(route)

{

alert('Distance from Seattle to Microsoft :'+route.Itinerary.Distance);

totalDistance+=route.Itinerary.Distance;

map.GetRoute("Microsoft", "Redmond, Washington, United States",VEDistanceUnit.Miles, VERouteType.Shortest, onGotRoute2);

}

function onGotRoute2(route)

{

alert('Distance from Microsoft to Redmond:'+route.Itinerary.Distance);

totalDistance+=route.Itinerary.Distance;

alert('Total trip distance :'+totalDistance);

}

</script>

</head>

<body onload="GetMap();">

<div id='myMap' style="position:relative; width:550px; height:600px;"></div>

<br />

<div id="directionsResults" style="position:absolute; top:50px;left:600px"></div>

</body>

</html>

The above code calcualtes the distance between Seattle and Microsoft and Micrsoft and Redmond. The real problem will be when you have more than three points. In such case, either you call the call back function recursively or have a common function which keeps on adding the distance for every route untill you reach the last stop.






Re: multiple routes

pravin_kr

Greg,

I didnt know that V5 has been release. I am told to upgrade our current application on the latest version of map control. As most the forums i visited, said that V5 is yet to released. Can you please provide me a link for getting any information on V5.

Also, how can we capture SVG polyline or the array of latlong points thourgh which the routes is traversed. The callback function just return a route object with general information about the route and its itineraries.

Well, if MS provides multi-points route feature in thier latest verion..that will certainly help all of us.






Re: multiple routes

Harvester

Unfortunately there isn't much info on V5 available yet. If you setup Firebug in Firefox and sniff around local.live.com you'll get the latest version of the control. Or try replacing the V4 in the SDK mapcontrol include with a V5.

The SDK for V5 isn't available yet, and I don't exactly when it will be, and probably couldn't say if I did (I've got no idea if I'm indirectly under an NDA or not!). It's soon, is all I'm going to say for now. Some things have changed quite drastically, like how pushpins/lines/etc are created, though backward compatibility is maintained with V4 for now. Events are also much improved, I think.

Anyway, the SVG polyline is there after the GetRoute call. Use Firebug to find it attached to the SVG object. It has a bunch of x,y pairs that I assumed were pixels and call to the map to convert each pair (pixel) to a latlong will get you the string of latlongs that can be used to build a line. I didn't get that far, but it looked possible. Repeat for each getRoute call and you'll maybe have the ability to create a big long line representing your route and if you've been storing the RouteSegments also you can mark the directions appropriately.

Totally off the cuff and untested, but as long as the initial assumption that those x/y pairs in the SVG polyline actually map to pixels correctly holds it should work.

Cheers,

Greg





Re: multiple routes

sathish_indian

Hi pravin,

Thank you very much..This code helped me a lot. But i have to pass an array of latitude and longitude values from database. I am trying with the

Recursive function. But facing problem in passing the values. Now I am following the below method.. But its not a good one...

Do you have any idea. .Pls inform me....

function LatLong_callback(res) //res = will have the array values

{

if(res.error != null)

{

alert(res.error);

return;

}

Arrayvalues = res.value.split("*");

var i = 0;

//var 'route' +i = ArrayvaluesIdea.split(",");

route1 = ArrayvaluesIdea.split(":");

route2 = Arrayvalues[i+1].split(":");

route3 = Arrayvalues[i+2].split(":");

route4 = Arrayvalues[i+3].split(":");

displayRoute(route1[0],route1[1]);

}

function displayRoute(lat1,long1)

{

map.GetRoute(new VELatLong(lat1,long1),form1.lstaddress.value,VEDistanceUnit.Miles,VERouteType.Shortest,ShowDistance);

}

function ShowDistance(route)

{

count += 1;

distance += route.Itinerary.Distance;

alert("Distance : " + distance);

if(count == 1)

{

displayRoute((route2[0],route2[1]);

}

else if(count == 2)

{

displayRoute(route3[0],route3[1]);

}

}






Re: multiple routes

pravin_kr

Sathish,

Since there is no way by which you can specify all your points in a route (as it takes only two points), you cant avoid this iteration. As you know, V5 has been officially released, you can explore this new version to look for your requirements.