calculateTotalPerimeter static method

double calculateTotalPerimeter(
  1. List<LatLng> points
)

Calculates the total perimeter (in meters) of a list of LatLng points.

For polygons, the first and last points are implicitly connected to close the shape. For polylines (2 points), only one segment is measured.

Returns 0.0 if fewer than 2 points are provided.

Implementation

static double calculateTotalPerimeter(List<LatLng> points) {
  double sum = 0;
  for (int i = 0; i < points.length; i++) {
    final start = points[i];
    final end = points[(i + 1) % points.length];
    if (points.length < 3 && i == points.length - 1) break;
    sum += Geolocator.distanceBetween(
      start.latitude,
      start.longitude,
      end.latitude,
      end.longitude,
    );
  }
  return sum;
}