length property
double
get
length
Returns the LineString's length in meters. The length is calculated using the Haversine formula.
Example:
LineString([Coordinate(1, 2), Coordinate(3, 4)]).length; // 314283.2550736839
Implementation
double get length {
double getLength(List<Coordinate> coordinates) {
if (coordinates.length < 2) {
return 0.0;
}
double length = 0.0;
for (int i = 0; i < coordinates.length - 1; i++) {
length += coordinates[i].distanceTo(coordinates[i + 1]);
}
return length;
}
return coordinates.length > 1 ? getLength(coordinates) : 0.0;
}