Skip to content

Instantly share code, notes, and snippets.

@xantiagoma
Created February 2, 2021 23:01
Show Gist options
  • Save xantiagoma/2d181c11526fe8ab1406ce18c9ced325 to your computer and use it in GitHub Desktop.
Save xantiagoma/2d181c11526fe8ab1406ce18c9ced325 to your computer and use it in GitHub Desktop.
L.Polyline = L.Polyline.include({
getDistance: function(system) {
// distance in meters
var mDistanse = 0,
length = this._latlngs.length;
for (var i = 1; i < length; i++) {
mDistanse += this._latlngs[i].distanceTo(this._latlngs[i - 1]);
}
// optional
if (system === 'imperial') {
return mDistanse / 1609.34;
} else {
return mDistanse / 1000;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment