“移动”从LatLonA到LatLonB(WGS84)的#米(地面)

问题描述:

我需要C#中的一个函数来执行以下操作:从gps-point A向gps-point B的方向移动50米,并计算GPS这一点的协调员。“移动”从LatLonA到LatLonB(WGS84)的#米(地面)

比如我有两个坐标:

LatLon LatLonA = new LatLon(51.83966, 5.04631); // Latitude 51.83966, Longitude 5.04631 
LatLon LatLonB = new LatLon(51.84172, 5.01961); // Latitude 51.84172, Longitude 5.01961 

我想是这样的功能:

function LatLon MoveTowards(LatLon A, LatLon B, double MetersOverGround) 
{ 
    //code here 
} 

该函数将返回坐标为x米远离在方向B.

+0

我用haversine公式之前计算点之间的距离,但我只是不知道如何收官的作品,我问路的算法... – frankhommers

地球不是一个球体,甚至不是一个椭圆。如果不购买商业图书馆,你可以期望的最好结果是近似值(对于大多数人来说是足够好的)。

您可以先查看Haversine formulathis page将有很大的帮助。

或者,如果你想有一个商业库,我已经使用ProLat取得了巨大成功

+0

我用的Haversine公式计算之前点之间的距离。近似就足够了。 – frankhommers

这是你想要的。只需使用Math.Atan2即可获得您A-to-B矢量的方位并获得bearing参数。

/// <summary> 
    /// Calculates the end-point from a given source at a given range (meters) and bearing (degrees). 
    /// This methods uses simple geometry equations to calculate the end-point. 
    /// </summary> 
    /// <param name="source">Point of origin</param> 
    /// <param name="range">Range in meters</param> 
    /// <param name="bearing">Bearing in degrees</param> 
    /// <returns>End-point from the source given the desired range and bearing.</returns> 
    public static PointLatLng CalculateDerivedPosition(PointLatLng source, double range, double bearing) 
    { 
     double latA = source.Lat * DEGREES_TO_RADIANS; 
     double lonA = source.Lng * DEGREES_TO_RADIANS; 
     double angularDistance = range/EARTH_RADIUS_M; 
     double trueCourse = bearing * DEGREES_TO_RADIANS; 

     double lat = Math.Asin(
      Math.Sin(latA) * Math.Cos(angularDistance) + 
      Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse)); 

     double dlon = Math.Atan2(
      Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA), 
      Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat)); 

     double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI; 

     return new PointLatLng(
      lat/DEGREES_TO_RADIANS, 
      lon/DEGREES_TO_RADIANS); 
    }