diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 47d40698..329b731d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -169,9 +169,9 @@ module ApplicationHelper end def point_speed(speed) - return speed if speed.to_i <= 0 - - speed * 3.6 + return "–" if speed.nil? || speed.to_f <= 0 + speed = speed.to_f + "#{(speed * 3.6).round(1)}" end def days_left(active_until) diff --git a/app/javascript/maps/helpers.js b/app/javascript/maps/helpers.js index 403aa698..a4cb806d 100644 --- a/app/javascript/maps/helpers.js +++ b/app/javascript/maps/helpers.js @@ -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; diff --git a/app/views/points/_point.html.erb b/app/views/points/_point.html.erb index 30b9a861..41ea2b67 100644 --- a/app/views/points/_point.html.erb +++ b/app/views/points/_point.html.erb @@ -13,7 +13,7 @@ } %> -