lil romeo


I am trying to record the start and end location of a route. I see that the GetRoute method is supposed to return a VERoute object, and I know that i have to get this information from this object. The question I have is how to actually store the VERoute object that is returned. From the documentation I tried two options, but neither of them work:

Option 1:

var myRoute = map.GetRoute("Space Needle", "Microsoft", null, null, null;
var start = myRoute.StartLocation.LatLong;
var end = myRoute.EndLocation.LatLong;

Option 2:
...
map.GetRoute("Space Needle", "Microsoft", null, null, "onRouteReturned");
...
//later on in the code
function onRouteReturned( myRoute )
{
var start = myRoute.StartLocation.LatLong;
var end = myRoute.EndLocation.LatLong;
}

I'm also new to javascript, so maybe I am completely off base.
Any help would be appreciated.




Re: Recording the start and end location of a route.

Dario Aznar


Hi lil,
you can get (and then save or do whatever you want to do with the data) doing like that:

startPointDescription=myRoute.StartLocation.Address; //this is the description of the start
endPointDescription=myRoute.EndLocation.Address; //this is the description of the end
startPointLatLong=myRoute.StartLocation.LatLong; //this is a latlong object of the start
endPointLatLong=myRoute.EndLocation.LatLong; //this is a latlong object of the end
if you want to acces the latitudes and longitudes, you then have to write:
startPointLatLong.Latitude //decimal value with the start point latitude
startPointLatLong.Longitude //decimal value with the start point longitude

hope it helps

Dario, from Argentina





Re: Recording the start and end location of a route.

Derek Chan

Looks like the problem is being in the quotes around your "onRouteReturned" in this line:

map.GetRoute("Space Needle", "Microsoft", null, null, "onRouteReturned");

Should be:

map.GetRoute("Space Needle", "Microsoft", null, null, onRouteReturned);

But it would help to see your entire file to duplicate your problem.  Anyhow below I've made some sample code which does what you need.

<html>
<head>
    <title>Virtual Earth - Driving Directions Bug</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>  
        
        var map = null;
        var myRoute;        
        function GetMap()
{
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(47.627595506391756,-122.24291235208511), 5, "r", false,null, false);
         map.GetRoute("Space Needle", "Microsoft",VEDistanceUnit.Kilometers,null,DisplayRoute);
        }
       
        function DisplayRoute(route)
{       
  myRoute = route;
  alert(myRoute.StartLocation.LatLong.Latitude);
  alert(myRoute.StartLocation.LatLong.Longitude);
}       
    </script>
</head>
<body onload="GetMap();">
    <div id="myMap" style="position:relative; width:400px; height:400px;"></div> 
</body>
</html>

After the route loads, you should see the lat/longs appear in a pop-up alert. 





Re: Recording the start and end location of a route.

lil romeo

Yes Derek, removing the quotations was what the problem was.

Thanks!