@sports-alliance/sports-lib
Version:
A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc
31 lines (30 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeoLibAdapter = void 0;
const geolib_1 = require("geolib");
class GeoLibAdapter {
constructor() {
this.findNearest = geolib_1.findNearest;
}
getDistance(positionArray, precise = false, accuracy = 0.1) {
let distance = 0;
const excludeFirstPointsArray = positionArray.slice(1);
let firstPosition = positionArray[0];
for (const nextPosition of excludeFirstPointsArray) {
const firstPositionAsDecimal = {
longitude: firstPosition.longitudeDegrees,
latitude: firstPosition.latitudeDegrees
};
const nextPositionAsDecimal = {
longitude: nextPosition.longitudeDegrees,
latitude: nextPosition.latitudeDegrees
};
distance += precise
? (0, geolib_1.getPreciseDistance)(firstPositionAsDecimal, nextPositionAsDecimal, accuracy)
: (0, geolib_1.getDistance)(firstPositionAsDecimal, nextPositionAsDecimal, accuracy);
firstPosition = nextPosition;
}
return distance;
}
}
exports.GeoLibAdapter = GeoLibAdapter;