我正在使用bing地图。至于现在,它绘制了两个地点之间的界线,但它使用了道路。我希望它是飞机视图,这样它就可以画出点之间的直线并告诉我它们之间的距离。我现在正在使用它:
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);
我将坐标放在lat1和lon1中。
答案 0 :(得分:3)
我们的阿拉斯泰尔同事写了一篇文章,在Bing Maps V7上绘制测地线(大圆)。我很确定你可以从他的文章中获得重要的东西并调整JavaScript代码,使其适用于你的C#控件。
请参阅文章:http://alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/
以下是您应该能够在C#中适应的JavaScript代码:
// 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;
}