Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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# 利用经纬度计算多边形面积_C#_Google Maps_Xamarin_Geolocation - Fatal编程技术网

C# 利用经纬度计算多边形面积

C# 利用经纬度计算多边形面积,c#,google-maps,xamarin,geolocation,C#,Google Maps,Xamarin,Geolocation,我正在使用我在这篇文章中找到的解决方案: 有点不对劲,因为我得到的值不是真实的。例如,我们知道一个足球场应该有5300.00平方米左右,对吗?但计算结果为5759154.21 代码如下: private static double CalculatePolygonArea(IList<Position> coordinates) { double area = 0; if (coordinates.Count > 2)

我正在使用我在这篇文章中找到的解决方案:

有点不对劲,因为我得到的值不是真实的。例如,我们知道一个足球场应该有5300.00平方米左右,对吗?但计算结果为5759154.21

代码如下:

    private static double CalculatePolygonArea(IList<Position> coordinates)
    {
        double area = 0;

        if (coordinates.Count > 2)
        {
            for (var i = 0; i < coordinates.Count - 1; i++)
            {
                Position p1 = coordinates[i];
                Position p2 = coordinates[i + 1];
                area += (ConvertToRadian(p2.Longitude) - ConvertToRadian(p1.Longitude)) * (2 + Math.Sin(ConvertToRadian(p1.Latitude)) + Math.Sin(ConvertToRadian(p2.Latitude)));
            }

            area = area * 6378137 * 6378137 / 2;
        }

        return Math.Abs(area);
    }

    private static double ConvertToRadian(double input)
    {
        return input * Math.PI / 180;
    }
专用静态双计算多边形区域(IList坐标)
{
双面积=0;
如果(坐标数>2)
{
对于(变量i=0;i

这里有什么问题?有什么帮助吗?

您使用的面积计算完全错误-/

我使用谷歌Android地图UTIL中的方法

注意:Google的Java代码在Apache许可证2.0版下,我将其转换为C#

在我的一个应用程序中查找足球场,我得到:4461,不太像实际的5531,但使用谷歌地图照片也不错

这里只是
计算信号区域

public static class SphericalUtil
{
    const double EARTH_RADIUS = 6371009;

    static double ToRadians(double input)
    {
        return input / 180.0 * Math.PI;
    }

    public static double ComputeSignedArea(IList<LatLng> path)
    {
        return ComputeSignedArea(path, EARTH_RADIUS);
    }

    static double ComputeSignedArea(IList<LatLng> path, double radius)
    {
        int size = path.Count;
        if (size < 3) { return 0; }
        double total = 0;
        var prev = path[size - 1];
        double prevTanLat = Math.Tan((Math.PI / 2 - ToRadians(prev.Latitude)) / 2);
        double prevLng = ToRadians(prev.Longitude);

        foreach (var point in path)
        {
            double tanLat = Math.Tan((Math.PI / 2 - ToRadians(point.Latitude)) / 2);
            double lng = ToRadians(point.Longitude);
            total += PolarTriangleArea(tanLat, lng, prevTanLat, prevLng);
            prevTanLat = tanLat;
            prevLng = lng;
        }
        return total * (radius * radius);
    }

    static double PolarTriangleArea(double tan1, double lng1, double tan2, double lng2)
    {
        double deltaLng = lng1 - lng2;
        double t = tan1 * tan2;
        return 2 * Math.Atan2(t * Math.Sin(deltaLng), 1 + t * Math.Cos(deltaLng));
    }
}
公共静态类SphereCalutil
{
常数双接地半径=6371009;
静态双toradian(双输入)
{
返回输入/180.0*Math.PI;
}
公共静态双计算指定区域(IList路径)
{
返回计算信号区域(路径、地球半径);
}
静态双计算指定区域(IList路径,双半径)
{
int size=path.Count;
如果(大小<3){返回0;}
双倍合计=0;
var-prev=路径[size-1];
double prevTanLat=Math.Tan((Math.PI/2-ToRadians(prev.lation))/2);
双经度=环面(前经度);
foreach(路径中的变量点)
{
双tanLat=Math.Tan((Math.PI/2-环面(点纬度))/2);
双lng=托拉迪安(点经度);
总面积+=极地三角区(坦拉特、液化天然气、普雷瓦坦拉特、普雷瓦坦拉特);
prevTanLat=tanLat;
prevLng=液化天然气;
}
返回总*(半径*半径);
}
静态双极化三角形区域(双tan1、双lng1、双tan2、双lng2)
{
双deltaLng=lng1-lng2;
双t=tan1*tan2;
返回2*Math.Atan2(t*Math.Sin(deltaLng),1+t*Math.Cos(deltaLng));
}
}

你的4分值是多少?@joseluisgonzalezclua没问题,很高兴这有帮助