[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1410
  • Last Modified:

Distance between 2 points on a bing map

Hi,

I am using a webbrowser control on a winform to host a bing map.
I need 2 things:

1) I want distance between 2 points.
2) I want a route between 2 points on the map.

How can i do this?

Thanks
0
shahjagat
Asked:
shahjagat
2 Solutions
 
ullfindsmitCommented:
Check out http://www.microsoft.com/maps/isdk/ajax/


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
      <script type="text/javascript">
         var map = null;
         
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap();
         
            var options = new VERouteOptions();
            options.RouteCallback = onGotRoute;
            map.GetDirections(["Microsoft", "Everett WA", "Bellingham WA"], 
                               options);
         }

         function onGotRoute(route)
         {
           // Unroll route
           var legs     = route.RouteLegs;
           var turns    = "Total distance: " + route.Distance.toFixed(1) + " mi\n";
           var numTurns = 0;
           var leg      = null;

           // Get intermediate legs
            for(var i = 0; i < legs.length; i++)
            {
               // Get this leg so we don't have to derefernce multiple times
               leg = legs[i];  // Leg is a VERouteLeg object
                  
               // Unroll each intermediate leg
               var turn = null;  // The itinerary leg
                  
               for(var j = 0; j < leg.Itinerary.Items.length; j ++)
               {
                  turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
                  numTurns++;
                  turns += numTurns + ".\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)\n";
               }
            }

            alert(turns);
         }
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
   </body>
</html>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now