我正在使用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。
我们的Alastair同事写了一篇文章,在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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句