computeLength static method

double computeLength(
  1. List<Point<num>> path
)

Returns the length of the given path, in meters, on Earth.

Implementation

static double computeLength(List<Point> path) {
  if (path.length < 2) {
    return 0;
  }

  double length = 0;
  Point prev = path[0];
  double prevLat = toRadians(prev.x);
  double prevLng = toRadians(prev.y);
  for (final point in path) {
    double lat = toRadians(point.x);
    double lng = toRadians(point.y);
    length += distanceRadians(prevLat, prevLng, lat, lng);
    prevLat = lat;
    prevLng = lng;
  }
  return length * MathUtils.earthRadius;
}