2012-06-28 2 views
0

포인트를 입력하고 싶은 위도와 경도 좌표가있는 포인트 목록이 X에 있습니다. 가장 가까운 3 개의리스트 멤버를 결정하는 알고리즘이 도움이 필요합니다.위도와 경도로 주어진 점에 가장 가까운 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; 
} 
관련 문제