diff options
-rwxr-xr-x | index.html | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -111,7 +111,21 @@ } } - const remainingCoords = coords.slice(closestIndex); + // After finding closestIndex + const lookahead = 10; + let forwardIndex = closestIndex; + + for (let i = closestIndex + 1; i < Math.min(closestIndex + lookahead, coords.length); i++) { + const [lat, lon] = coords[i].split(',').map(Number); + const dist = getDistance(userLat, userLon, lat, lon); + // Prefer slightly farther point if it's still reasonably close and farther along + if (dist < minDist * 1.5) { + forwardIndex = i; + minDist = dist; + } + } + + const remainingCoords = coords.slice(forwardIndex); const selectedCoords = downsampleWaypoints(remainingCoords); const startCoord = "Current+Location"; |