Created
April 30, 2021 08:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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