calculateArea static method

double calculateArea(
  1. List<LatLng> points
)

Calculates the approximate geodesic area (in square meters) of a closed polygon.

Uses the LatLng list to compute the area using a spherical formula based on the Earth's radius.

Returns 0.0 if fewer than 3 points are provided (not a closed shape).

Implementation

static double calculateArea(List<LatLng> points) {
  if (points.length < 3) return 0.0;

  double area = 0.0;
  for (int i = 0; i < points.length; i++) {
    final p1 = points[i];
    final p2 = points[(i + 1) % points.length];
    area += degreesToRadians(p2.longitude - p1.longitude) *
        (2 + sin(degreesToRadians(p1.latitude)) + sin(degreesToRadians(p2.latitude)));
  }

  area = area * 6378137 * 6378137 / 2.0; // 6378137 = Earth's radius in meters
  return area.abs();
}