c# - 方向基于 2 个纬度、经度点

标签 c# google-maps latitude-longitude computational-geometry google-earth

我正在寻找一个可以发送 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/

相关文章:

javascript - 如何删除 Google map api3 中的单个标记

c# - 从类中删除或处理一次性

c# - Newtonsoft 在基类的序列化中包含子属性?

Android-谷歌地图 V2 : Trace route from current position to an other destination

java - 代号为One的Google Maps项目将无法构建

c# - 在巴基斯坦的 Twitter Streaming API 中传递经度和纬度

google-maps - 给定一个 lat/lng 坐标,计算 10 公里区域的最小和最大 lat/lng 值

javascript - 对中间循环数字使用最终循环值

c# - 类型 'Parse' 中不存在适用的方法 'DateTime'

c# - 比较两个 Linq 对象