Straight line between two points?

I want to plot lines between points on a map. I am trying to create an origin and destination map and can plot my push pins ok for the origin and destination, but I need to have lines connecting the two, not route lines, just straight lines so I know 1 point is associated with another. Haven't seen any examples of how to do this.


Answer this question

Straight line between two points?

  • Nightmare_BE

    Awesome, thanks!
  • Tom_Liu

    See the interactive SDK (http://dev.live.com/virtualearth/sdk/), under "Draw Lines". Basically, you just create a VEPolyline (http://msdn.microsoft.com/library/en-us/VEMapControl/HTML/C_Namespace_VEPolyline_ctor.asp frame=true) and specify the start and end points. Very easy!

     

    Here's a complete code snippet that draws a straight red line across the top of Wyoming:

     

    <html>
       <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <script src="
    http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
          <script>
             var map = null;
            
             function GetMap()
             {
                map = new VEMap('myMap');
                map.LoadMap();
             }  
            
             function DrawPoly(id,points,width,color)
             {
                poly = new VEPolyline(id,points);
                poly.SetWidth(width);
                poly.SetColor(color);
                map.AddPolyline(poly);
             }
          </script>
       </head>
       <body onload="GetMap();">
          <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
          <INPUT id="draw" type="button" value="Draw a Line" onclick="DrawPoly(
                   '1',
                   [new VELatLong(45.01188,-111.06687),
                   new VELatLong(45.01534,-104.06324)],
                   2,
                   new VEColor(255,0,0,1)
                   );">
       </body>
    </html>


  • Straight line between two points?