From 13f2a203c4c6194da2feb5e5f41241fb8ce3a7bc Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Thu, 14 Sep 2023 23:51:59 -0300 Subject: [PATCH] fix: heading speed w3c spec (#270) * CB-11462: (all) Make sure Coordinates#speed follows the w3c specification. Speed can have a negative value on iOS devices when the OS is not able to determine the current speed. This is against the w3c specification. Which only allows null and a number value >= 0. See the following links for further informations: * https://dev.w3.org/geo/api/spec-source.html#speed * https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/#//apple_ref/occ/instp/CLLocation/speed * CB-11462: (all) Make sure Coordinates#heading follows the w3c specification. Heading (course) can have a negative value on iOS devices when the OS is not able to determine the current heading. This is against the w3c specification. Which only allows null and a number value >= 0 and <= 360. See the following links for further informations: * https://dev.w3.org/geo/api/spec-source.html#heading * https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/#//apple_ref/occ/instp/CLLocation/course --------- Co-authored-by: Malte Legenhausen --- www/Coordinates.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/Coordinates.js b/www/Coordinates.js index 59ee6e2c..6ef21662 100644 --- a/www/Coordinates.js +++ b/www/Coordinates.js @@ -50,11 +50,11 @@ const Coordinates = function (lat, lng, alt, acc, head, vel, altacc) { /** * The direction the device is moving at the position. */ - this.heading = head !== undefined ? head : null; + this.heading = (typeof head === 'number' && head >= 0 && head <= 360 ? head : null); /** * The velocity with which the device is moving at the position. */ - this.speed = vel !== undefined ? vel : null; + this.speed = (typeof vel === 'number' && vel >= 0 ? vel : null); if (this.speed === 0 || this.speed === null) { this.heading = NaN;