Insert a Virtual Earth Map in your asp.net page - Part 3

by Emanuele 6/20/2008 3:30:00 PM

Another interesting thing in Microsoft Virtual Earth is calculate the route between two points.
The method for do this is GetDirections.
This method has two parameters.
The first is an array with the list of the points.
The second is a VERouteOptions object that specified some options.
The options is:

DistanceUnit: enum (Kilometer, Miles)
DrawRoute: if true, the function draws the road on the map
RouteColor: the color of the route
RouteMode: enum VERouteMode (Walking, Driving)
RouteOptimize: enum (MinimizeTime, MinimizeDistance)
SetBestMapView: if true, the map moves on your route
RouteCallback: the function invoked when the search is finished

Add this html code under the map (see the first or second article)

<input id="txtStart" type="text" name="txtStart" value="Piana del Sole, Roma, Lazio, Italy"/>
<input id="txtEnd" type="text" name="txtEnd" value="Piazza del Popolo (historical site), Rome, Lazio, Italy"/>
<input id="find" type="button" value="Find" name="GetRoute"
       onclick="GetRoute();"/>

Add this javascript function:

function GetRoute(){
  try{
    var options = new VERouteOptions();
    options.DrawRoute = true;
    options.SetBestMapView = true;
    options.DistanceUnit = VERouteDistanceUnit.Kilometer;
    map.GetDirections([document.getElementById('txtStart').value,
      document.getElementById('txtEnd').value], options);
  }
  catch(e)
  {
    alert(e.message);
  }
}

In the attachment you find the example page that I created.

VirtualEarth3.zip (1.13 kb)

Enjoy!

Related posts



Powered by BlogEngine.NET 1.3.1.0
Theme by Emanuele Bartolesi

About the author

Name of author Emanuele Bartolesi
I'm a senior developer and project manager.

Contact me Contact me

Calendar

<<  December 2008  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in

Download Day 2008