Skip to content

Instantly share code, notes, and snippets.

@muellercornelius
Created April 30, 2021 08:27
Show Gist options
  • Save muellercornelius/19fef649170bec9767d1f4143e57418b to your computer and use it in GitHub Desktop.
Save muellercornelius/19fef649170bec9767d1f4143e57418b to your computer and use it in GitHub Desktop.
Calculate the length of a polyline using Geolocator and a Google Maps Polyline
Polyline track = new Polyline(polylineId: PolylineId("1"), points: [/*your track data*/]);
distance = 0;
for (int i = 0; i < track.points.length; i++) {
if (track.points.length > 1 && i > 0) {
LatLng startPoint = track.points[i - 1];
LatLng endPoint = track.points[i];
distance += Geolocator.distanceBetween(startPoint.latitude, startPoint.longitude, endPoint.latitude, endPoint.longitude);
}
}
print(distance);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment