using System.Collections.Generic;
public static void Main()
IList<LatLng> path = new List<LatLng>();
path.Add(new LatLng(-20.253605204701, -70.106903276165));
path.Add(new LatLng(-20.253818617830, -70.107765556612));
path.Add(new LatLng(-20.254495614967, -70.107654186777));
path.Add(new LatLng(-20.254400336391, -70.106938131964));
var resultado = SphericalUtil.ComputeSignedArea(path);
Console.WriteLine("Hello World " + resultado);
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)
if (size < 3) { return 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);
return total * (radius * radius);
static double PolarTriangleArea(double tan1, double lng1, double tan2, double lng2)
double deltaLng = lng1 - lng2;
return 2 * Math.Atan2(t * Math.Sin(deltaLng), 1 + t * Math.Cos(deltaLng));
public double Latitude {get;set;}
public double Longitude {get;set;}
public LatLng(double latitude, double longitude)
this.Latitude = latitude;
this.Longitude = longitude;