Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Lat和Long获得距离给定点最近的X点?_C#_Asp.net_Google Maps_Map - Fatal编程技术网

C# 如何使用Lat和Long获得距离给定点最近的X点?

C# 如何使用Lat和Long获得距离给定点最近的X点?,c#,asp.net,google-maps,map,C#,Asp.net,Google Maps,Map,我有一个带有纬度和经度坐标的点列表,我想从中输入一个点,比如X。我需要一个算法来帮助我确定离该点X最近的3个列表成员。你基本上可以将其作为一个3D最近点问题来处理。(我现在手头上没有横向/纵向到笛卡尔(x,y,z)的计算,但你可以通过谷歌很容易地找到) 您的班级代码: // Your list of points private List<LatLonPoint> _points = new List<LatLonPoint>(); public LatLonPoint

我有一个带有纬度和经度坐标的点列表,我想从中输入一个点,比如X。我需要一个算法来帮助我确定离该点X最近的3个列表成员。

你基本上可以将其作为一个3D最近点问题来处理。(我现在手头上没有横向/纵向到笛卡尔(x,y,z)的计算,但你可以通过谷歌很容易地找到)

您的班级代码:

// 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;
}
//您的点列表
私有列表_points=新列表();
公共LatLonPoint FindClosestPoint(LatLonPoint x)
{
var closestPoint=null;
double closestDistance=double.MaxValue;
foreach(latLonList中的var点)
{
双距离点=点距离(x);
if(距离点<最近距离)
{
闭合点=点;
最近距离=距离点;
}
}
返回闭合点;
}

我建议访问此页面:-这是一本有趣的读物。
// 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;
}