Expecho's .Net corner
All about software development

How to use the virtual earth winforms user control part 3: Driving directions

June 26, 2008 13:37 by Peter Bons

The Microsoft Virtual Earth service support getting driving directions to specific locations. A route can consist of a maximum of 25 waypoints.

The method VE_GetDirections() takes a List<> of SearchLocations (it will throw an exception if more than 25 objects are in the List<>). As a result it returns a RouteDirections object that holds all information about the directions. The RouteDirections.RouteLegs property contains detailed information about each direction:



RouteDirections rd = ucVEarth.VE_GetDirections(
        locations, // list of waypoints along the route
        true, // display the route on the map
        true, // center the map for best view
        VEarth.ucVEarth.RouteModeEnum.Driving, // are we walking or driving?
        VEarth.ucVEarth.DistanceUnitEnum.Kilometers); // show distance in miles or kilometers?
    );

    lstDirections.Items.Clear();
    lstDirections.Items.Add(String.Format("Total distance: {0}", rd.TotalDistance));
    lstDirections.Items.Add(String.Format("Total duration: {0}", rd.TotalDuration));
    lstDirections.Items.Add("");

    // Iterate through all route parts
    foreach(RouteLeg rl in rd.RouteLegs)
    {
        lstDirections.Items.Add(String.Format("{0} - {1} - {2}", rl.Description, rl.Distance, rl.Duration));
    }

The list of SearchLocation objects can contain both SearchLocation objects with set Latitude and Longitude properties and objects with the Where or What property set.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

January 12. 2009 07:43

Busby SEO Test

great tip, thank you for sharing

Busby SEO Test

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 4. 2009 18:20