Question

I'm using bing maps. As for now it draws the line between the two locations but it uses the roads. I want it to be airplane view so that it just draws the straight line between the points and tells me the distance between them. I'm using this now:

var startwaypoint = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(lat1, lon1) });
bingDirections.addWaypoint(startwaypoint);
// end
var endwaypoint = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(lat2, lon2) });
bingDirections.addWaypoint(endwaypoint);

Where I put in the coordinates as lat1 and lon1.

Was it helpful?

Solution

Our fellow Alastair has written an article to draw geodesic lines (great circle) on Bing Maps V7. I'm pretty sure you can get the important things out of his article and adapt the JavaScript code so it works on your C# control.

See the article: http://alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/

Here is the JavaScript code you should be able to adapt in C#:

    // Creates geodesic approximation of the lines drawn between an array
// of points, by dividing each line into a number of segments.
function ToGeodesic(points, n) {
  if (!n) { n = 32 }; // The number of line segments to use
  var locs = new Array();
  for (var i = 0; i < points.length - 1; i++) {
    with (Math) {
      // Convert coordinates from degrees to Radians
      var lat1 = points[i].latitude * (PI / 180);
      var lon1 = points[i].longitude * (PI / 180);
      var lat2 = points[i + 1].latitude * (PI / 180);
      var lon2 = points[i + 1].longitude * (PI / 180);
      // Calculate the total extent of the route
      var d = 2 * asin(sqrt(pow((sin((lat1 - lat2) / 2)), 2) + cos(lat1) * cos(lat2) * pow((sin((lon1 - lon2) / 2)), 2)));
      // Calculate  positions at fixed intervals along the route
      for (var k = 0; k <= n; k++) {
        var f = (k / n);
        var A = sin((1 - f) * d) / sin(d);
        var B = sin(f * d) / sin(d);
        // Obtain 3D Cartesian coordinates of each point
        var x = A * cos(lat1) * cos(lon1) + B * cos(lat2) * cos(lon2);
        var y = A * cos(lat1) * sin(lon1) + B * cos(lat2) * sin(lon2);
        var z = A * sin(lat1) + B * sin(lat2);
        // Convert these to latitude/longitude
        var lat = atan2(z, sqrt(pow(x, 2) + pow(y, 2)));
        var lon = atan2(y, x);
        // Create a Location (remember to convert back to degrees)
        var p = new Microsoft.Maps.Location(lat / (PI / 180), lon / (PI / 180));
        // Add this to the array
        locs.push(p);
      }
    }
  }
  return locs;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top