Skip to content

Commit efae6e2

Browse files
committed
Fix: defensive coding for coordinate format in route suggestion
1 parent 52dd027 commit efae6e2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/app/page.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,14 @@ ${gpxPoints}
418418
centerLat = selectedStartPoint[1];
419419
centerLon = selectedStartPoint[0];
420420
} else if (routes.length > 0) {
421-
const allCoords = routes.flatMap(r => r.coordinates);
422-
centerLat = allCoords.reduce((sum, [, lat]) => sum + lat, 0) / allCoords.length;
423-
centerLon = allCoords.reduce((sum, [lon]) => sum + lon, 0) / allCoords.length;
421+
const allCoords = routes.flatMap(r => r.coordinates || []);
422+
if (allCoords.length > 0 && Array.isArray(allCoords[0])) {
423+
centerLat = allCoords.reduce((sum, coord) => sum + (Array.isArray(coord) ? coord[1] : 0), 0) / allCoords.length;
424+
centerLon = allCoords.reduce((sum, coord) => sum + (Array.isArray(coord) ? coord[0] : 0), 0) / allCoords.length;
425+
} else {
426+
centerLat = 59.3293;
427+
centerLon = 18.0686;
428+
}
424429
} else {
425430
centerLat = 59.3293;
426431
centerLon = 18.0686;

0 commit comments

Comments
 (0)