我正在寻找一个可以发送 2 Lat, Longs 的函数。 1 纬度、经度是我的基准,第二个是我要确定它是 N、S、E 还是西。或者我必须去 NW,N,NE,EN,E,ES,SE,S,SW,WS,W,WN 吗?无论哪种方式,有人在 C# 中有类似的东西吗?
最佳答案
首先你可以计算大圆方位角
θ = atan2( sin(Δλ).cos(φ2), cos(φ1).sin(φ2) − sin(φ1).cos(φ2).cos(Δλ) )
JavaScript(可轻松转换为 C#):
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = Math.atan2(y, x).toDeg();
http://www.movable-type.co.uk/scripts/latlong.html
然后将结果分割成所需的基本方向,例如如果方位在 -45(315 度)度和 45 度之间,则为北,依此类推。
public string Cardinal(double degrees)
{
if (degrees > 315.0 || degrees < 45.0)
{
return "N";
}
else if (degrees >= 45.0 && degrees < 90)
{
return "E";
}
// Etc for the whole 360 degrees. Segment finer if you want NW, WNW, etc.
}
关于c# - 方向基于 2 个纬度、经度点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13941352/