Update helpers.js

Updated `formatSpeed` in `helpers.js` to correctly assume incoming speed is in m/s and convert to km/h before formatting.
This commit is contained in:
Victor Goncharov 2025-06-04 00:12:32 +02:00 committed by GitHub
parent b05ab63f28
commit 69b628a487
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -66,15 +66,18 @@ export function formatDate(timestamp, timezone) {
return date.toLocaleString(locale, { timeZone: timezone });
}
export function formatSpeed(speedKmh, unit = 'km') {
export function formatSpeed(speedMs, unit = 'km') {
const speedKmh = speedMs * 3.6; // Convert m/s to km/h
if (unit === 'km') {
return `${Math.round(speedKmh)} km/h`;
} else {
const speedMph = speedKmh * 0.621371; // Convert km/h to mph
const speedMph = speedKmh * 0.621371;
return `${Math.round(speedMph)} mph`;
}
}
export function haversineDistance(lat1, lon1, lat2, lon2, unit = 'km') {
// Haversine formula to calculate the distance between two points
const toRad = (x) => (x * Math.PI) / 180;