2012-06-28 31 views
0

我有經緯度座標的點列表,我想從中輸入一個點X.我需要幫助提出一個算法來確定最接近的3個列表成員到那個點x。如何用Lat和Long獲得最近的X點到給定點?

+0

我建議訪問此頁面:http://www.movable-type.co.uk/scripts/latlong.html - 這是讀取interesing。 –

+0

[你有什麼嘗試?](http://whathaveyoutried.com) – Mizipzor

回答

1

你基本上可以把它作爲一個3D最近點問題。 (我現在手邊沒有Lat/Lon to Cartesian(x,y,z)calc,但是你可以很容易地用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 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; 
} 
相關問題