Walking Directions Sample in VE 6.1


I love the big city. I spend a fair amount of time in downtown areas like New York, Seattle and San Francisco, so something like walking directions is a very valuable feature for me. I spend a lot of time in LA too, but who walks in LA?? You remember the MIssing Persons song, Walking in LA, “Nobody walks in LA.” I digress.


So, check out this new “routing” feature. My typical day in NYC starts at the Marriott Marquis in Midtown. I like to walk to Starbucks to get some diesel to help me compensate for the time difference when going East. Let’s say that instead of walking to one of the two that are kitty-corner from the hotel I chose to walk a bit further for a bit of exercise. So, I’m going to set my app up to route from the Marriott @ “1535 Broadway, New York, NY’ to  Starbucks @ ‘1166 Avenue Of The Americas, New York, NY.’


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
   <head>
      <title>Walking Directions Sample</title>
      <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>

      <!– saved from url=(0014)about:internet –>
      <script type=”text/javascript” src=”
http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1″></script>

      <script type=”text/javascript”>

      var map = null;
      var myLocations = new Array();
      myLocations[0] = “1535 Broadway, New York, NY”;

      myLocations[1] = “1166 Avenue Of The Americas, New York, NY”;
      function GetMap()
      {
         map = new VEMap(‘myMap:newmap’);
         map.LoadMap();
     GetWalkingRoute();
      }

     function GetWalkingRoute()
     {
    map.GetDirections(myLocations);

     }

      </script>
   </head>
   <body onload=”GetMap();”>
      <div id=’myMap:newmap’ style=”position:relative; width:800px; height:600px;”></div>
   </body>
</html>


This is the route you would see based on just a normal route calculation.


image


Now, let’s add the new VERouteMode Property to the VERouteOptions Class into the mix to specify walking directions. Two lines of code is all you need, but I don’t like the Cyan blue, so I’ll add on optional line of code to change the route line to Starbucks green too.


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
   <head>
      <title>Walking Directions Sample</title>
      <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>

      <!– saved from url=(0014)about:internet –>
      <script type=”text/javascript” src=”
http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1″></script>

      <script type=”text/javascript”>

      var map = null;
      var myLocations = new Array();
      myLocations[0] = “1535 Broadway, New York, NY”;

      myLocations[1] = “1166 Avenue Of The Americas, New York, NY”;
      function GetMap()
      {
         map = new VEMap(‘myMap:newmap’);
         map.LoadMap();
     GetWalkingRoute();
      }

     function GetWalkingRoute()
     {
    var myRouteOptions = new VERouteOptions();
    myRouteOptions.RouteMode = VERouteMode.Walking;
    myRouteOptions.RouteColor = new VEColor(0, 102, 51, .7);

    map.GetDirections(myLocations, myRouteOptions);

     }

      </script>
   </head>
   <body onload=”GetMap();”>
      <div id=’myMap:newmap’ style=”position:relative; width:800px; height:600px;”></div>
   </body>
</html>

Now this is getting some exercise! Wait…


image


Some notes about walking directions:



  • Walking directions will allow you to take one way streets regardless of the direction of travel.  However, it won’t route you through a park or through the lobby of a hotel to avoid the cold weather.h

  • There’s a limit of a 20 miles for a walking route.

  • We won’t route you onto a freeway or other hazardous roads – whew! If we do, please don’t walk there and send me a note before you try it.

  • Default for RouteMode is VERouteMode.Driving, so to use walking directions you have to specify it.

  • For more info on RouteMode check the SDK.

  • And, to answer the burning question, yes it works with multi-point routing so if I actually did want to exercise by running through central park after my latte (which I do) you just add additional locations to the array.

image


Go green – use walking directions.


CP

Comments (5)

  1. jz5 says:

    Hi.

    > There’s a limit of a 20 miles for a walking route.

    Is it correct? MSDN Library says the limit is 16km(=10miles)

  2. Virtual Earth 6.1, 道案内 GetDirections

  3. Chris Pendleton says:

    There are two distance checks that we do when computing walking directions.  The first is a Great Circle (straight line) distance between the start location and the end location.  If the GC distance is more than 16Km an error will be returned.  If the start and end coordinates are within 16Km, we will generate a route, but will fail if the distance of the route solution exceeds 32Km.  This second check is really looking for the same 16Km distance, but because we do a bi-directional search when computing a route, it is possible to find a 16Km route from the start that meets up with a 16Km route from the end to create a combine route of up to 32Km.  

    How can a route that has a GC distance less than 16Km still fail to generate a valid route?  Imagine a start location in Madison Park and a destination in Bellevue.  The GC distance is less than 16Km.  However, because of Lake Washington (and not being able to walk across the bridges), we’d have to generate a route that goes all the way around the lake, which would result in a route longer than 32Km.

    CP

  4. It’s been a crazy travel schedule and I’m just now getting a chance to do some blogging (and not for