calculateRouteDistance method
Calculates the distance between all points in a list
Implementation
String calculateRouteDistance(List<LatLng> points, {decimals}) {
double totalDistance = 0.0;
/// Defaults the number of decimals to 1 if not specified
decimals ??= 1;
/// Iterates through all points in the list and calculates
/// the distance between each point
for (int i = 0; i < points.length - 1; i++) {
totalDistance += _routeDistance(
points[i].latitude,
points[i].longitude,
points[i + 1].latitude,
points[i + 1].longitude,
);
}
print('TOTAL DISTANCE: ${totalDistance.toStringAsFixed(decimals)} km');
/// Returns the total distance in km
return '${totalDistance.toStringAsFixed(decimals)} km';
}