Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.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
在.NET core中查找两个坐标之间的距离_.net_Asp.net Core_.net Core_Geolocation_Geospatial - Fatal编程技术网

在.NET core中查找两个坐标之间的距离

在.NET core中查找两个坐标之间的距离,.net,asp.net-core,.net-core,geolocation,geospatial,.net,Asp.net Core,.net Core,Geolocation,Geospatial,我需要找到.NET core中两个坐标之间的距离。我试过使用下面提到的代码 var sCoord=新的地理坐标纬度,sLongitude; var eCoord=新的地理坐标纬度、长度 返回sCoord.getDistanceToeCord 但是,.NETCore似乎不支持GeoCoordination类。有没有其他精确的方法可以使用.NET core中的纬度和经度计算两个坐标之间的距离?GeoCoordination类是.NET framework中System.Device.dll的一部分。

我需要找到.NET core中两个坐标之间的距离。我试过使用下面提到的代码

var sCoord=新的地理坐标纬度,sLongitude; var eCoord=新的地理坐标纬度、长度

返回sCoord.getDistanceToeCord


但是,.NETCore似乎不支持GeoCoordination类。有没有其他精确的方法可以使用.NET core中的纬度和经度计算两个坐标之间的距离?

GeoCoordination类是.NET framework中System.Device.dll的一部分。但是,它在.Net Core中不受支持。我找到了另一种方法来计算两个坐标之间的距离

    public double CalculateDistance(Location point1, Location point2)
    {
        var d1 = point1.Latitude * (Math.PI / 180.0);
        var num1 = point1.Longitude * (Math.PI / 180.0);
        var d2 = point2.Latitude * (Math.PI / 180.0);
        var num2 = point2.Longitude * (Math.PI / 180.0) - num1;
        var d3 = Math.Pow(Math.Sin((d2 - d1) / 2.0), 2.0) +
                 Math.Cos(d1) * Math.Cos(d2) * Math.Pow(Math.Sin(num2 / 2.0), 2.0);
        return 6376500.0 * (2.0 * Math.Atan2(Math.Sqrt(d3), Math.Sqrt(1.0 - d3)));
    }
其中,点1和点2是具有坐标的2个点,位置是一个类,如下所示

public class Location
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }
}
请检查链接以获得另一种计算距离的方法,该方法给出的结果与上述代码相同-

GeoCoordination类是.net framework中System.Device.dll的一部分。但是,它在.Net Core中不受支持。我找到了另一种方法来计算两个坐标之间的距离

    public double CalculateDistance(Location point1, Location point2)
    {
        var d1 = point1.Latitude * (Math.PI / 180.0);
        var num1 = point1.Longitude * (Math.PI / 180.0);
        var d2 = point2.Latitude * (Math.PI / 180.0);
        var num2 = point2.Longitude * (Math.PI / 180.0) - num1;
        var d3 = Math.Pow(Math.Sin((d2 - d1) / 2.0), 2.0) +
                 Math.Cos(d1) * Math.Cos(d2) * Math.Pow(Math.Sin(num2 / 2.0), 2.0);
        return 6376500.0 * (2.0 * Math.Atan2(Math.Sqrt(d3), Math.Sqrt(1.0 - d3)));
    }
其中,点1和点2是具有坐标的2个点,位置是一个类,如下所示

public class Location
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }
}
请检查链接以获得另一种计算距离的方法,该方法给出的结果与上述代码相同-

GeoCoordination类是System.Device.dll的一部分,也是net framework中的一部分。此答案提供了一个不带System.Device.dll的独立解决方案GeoCoordination类是System.Device.dll的一部分,也是net framework中的一部分。此答案提供了一个不带System.Device.dll的独立解决方案供参考,上述方法以米为单位返回距离。此外,如果您能够在项目中利用多目标定位,Microsoft有一个.Net Core GeoLocation NuGet包:作为参考,上面的方法以米为单位返回距离。此外,如果您能够在项目中利用多目标定位,Microsoft有一个.Net Core GeoLocation NuGet包: