简体   繁体   English

如何用纬度和经度将X点最接近给定点?

[英]How to get nearest X points to a given point with Lat and Long?

我有一个具有经度和纬度坐标的点列表,我想从该点输入一个点,例如X。我需要一个算法来确定最接近该点x的3个列表成员。

You can basically just approach this as a 3D nearest point problem. 您基本上可以将其作为3D最近点问题来解决。 (I don't have the Lat / Lon to Cartesian (x,y,z) calc at hand right now, but you can easily find that using google). (我现在手边没有纬度/经度到直角坐标(x,y,z)的计算,但您可以使用Google轻松找到它)。

public class LatLonPoint
{
   public double Latitude { get; set; }
   public double Longitude { get; set; }

   public double X
   {
      get
      {
      .......
      }
   }

   public double Y ....
   public double Z .....

   public double DistanceTo(LatLonPoint point)
   {
     double dX = point.X - X;
     double dY = point.Y - Y;
     double dZ = point.Z - Z;

     return Math.Sqrt(dX * dX + dY * dY + dZ * dZ);
   }
}

Your class code: 您的课程代码:

// Your list of points
private List<LatLonPoint> _points = new List<LatLonPoint>();

public LatLonPoint FindClosestPoint(LatLonPoint x)
{
    var closestPoint = null;
    double closestDistance = double.MaxValue;

    foreach (var point in latLonList)
    {
        double distanceToPoint = point.DistanceTo(x);
        if (distanceToPoint < closestDistance)
        {
           closestPoint = point;
           closestDistance = distanceToPoint;
        }
    }

    return closestPoint;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 给定纬度/经度,从C#中的纬度/经度列表中找到最接近的纬度/经度对 - Given a lat/long, find the nearest lat/long pair from a list of lat/long in c# 如何找到给定纬度/经度以北 x 公里的纬度/经度? - How do I find the lat/long that is x km north of a given lat/long? 如何根据移动点和最近点获得抛物线形状 - How to get a parabola shape according to a moved point and nearest points 当另外两个点的经度和纬度已知时,计算该点的经度和纬度 - Calculate Long and Lat for a point when Long and Lat of two other points is known 尝试从起点计算纬度和经度给定的距离和方位 - Attempting to calculate lat and long given distance and bearing from start point 如何在给定点找到最近点(点(x,y),在不同点的列表中)? - How to find closest point (point being (x,y), in a list of different points) to a given point? 在没有起点的情况下将X / Y转换为纬度/经度 - Converting X/Y to Lat/Long without point of origin 当给定点的经度/纬度具有距离时获得一个点 - Get a point when having lon/lat of a given point with distance 使用lat long查找最近的机场 - Find nearest airport using lat long 如何在 C# 中按距离(以英里为单位)对给定纬度/经度的纬度/经度列表进行排序? - How to sort a list of lat/long by distance (in miles) from a given lat/long in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM