Fix distance calculation for GPX files without elevation data
Distance was only stored in the elevation profile array, which was empty when track points had no <ele> elements. Now computed via haversine independently and exposed as gpxData.distance. Tested: berlin-dresden-radweg-2021.gpx (5660 points, no elevation) now correctly reports 248.8 km. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ed2d04c248
commit
d5bcecb345
4 changed files with 8 additions and 11 deletions
|
|
@ -23,8 +23,7 @@ export async function createActivity(ownerId: string, input: ActivityInput) {
|
|||
if (input.gpx) {
|
||||
try {
|
||||
const gpxData = await parseGpxAsync(input.gpx);
|
||||
const profile = gpxData.elevation.profile;
|
||||
distance = profile.length > 0 ? Math.round(profile[profile.length - 1]!.distance) : null;
|
||||
distance = gpxData.distance || null;
|
||||
elevationGain = gpxData.elevation.gain;
|
||||
elevationLoss = gpxData.elevation.loss;
|
||||
|
||||
|
|
|
|||
|
|
@ -145,11 +145,7 @@ async function computeRouteStats(gpxString: string) {
|
|||
try {
|
||||
const gpxData = await parseGpxAsync(gpxString);
|
||||
return {
|
||||
distance: Math.round(
|
||||
gpxData.elevation.profile.length > 0
|
||||
? gpxData.elevation.profile[gpxData.elevation.profile.length - 1]!.distance
|
||||
: 0,
|
||||
),
|
||||
distance: gpxData.distance,
|
||||
elevationGain: gpxData.elevation.gain,
|
||||
elevationLoss: gpxData.elevation.loss,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue