Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Back for more (distance units on watch face)

ANSWERED

First off, can send a thank you to anyone who has already helped me in previous posts. I have learnt a lot in a short space of time but i'm back for more help.

I currently run 'Miles' on my clock faces, I do this by forcing the equation which turn meters into miles. This works well but I want to advance this a bit and base the distance on user settings (metric, us etc). Pulling user settings for 12/24 hr has worked a treat but I'm not quite getting there with units displaying.  

I understand it has to do with units.distance, but it's when i start the 'if and if else' i fear I may be swaying off track.

If someone could point me in the right direction that would be much appreciated. Thanks in advance.

Best Answer
1 BEST ANSWER

Accepted Solutions
import { units } from "user-settings";
var dist = 1234; // 1234m just for exampe
var distText; if (units.distance === "us") distText = Number(dist*0.000621371).toFixed(2)+"mi"; else distText = Number(dist*0.001).toFixed(2)+"km";

Try this ^

View best answer in original post

Best Answer
4 REPLIES 4
import { units } from "user-settings";
var dist = 1234; // 1234m just for exampe
var distText; if (units.distance === "us") distText = Number(dist*0.000621371).toFixed(2)+"mi"; else distText = Number(dist*0.001).toFixed(2)+"km";

Try this ^

Best Answer

Hello, I have tried fitting this into my code, I must be doing something wrong as I get nothing appearing on my watch face:

This is my current code, without any of the above included:

 

function updateDistance() {

let iDistance =(today.adjusted.distance || 0);
let iDistanc =(goals.distance || 0);
myDistance.text=(today.adjusted.distance || 0);
console.log(today.adjusted.distance);
console.log(units.distance);


var Distance = today.adjusted.distance;
myDistance.style.fill = calculateDistanceColor(Math.floor(iDistance/iDistanc * 100));
}

 

 

I assume I am just not relating to the right part of the function.

Best Answer
0 Votes

Seems to be a new issue, so it would be better to start a new thread.

Anyway: What happens, when you're not set the fill attribute? Do you see something?

What's the console log output?

Best Answer
0 Votes

Its ok, your code has worked. I fear tiredness was my issue, came back to it today after a nights sleep and it works a treat, including the fill, so intragated my code, no issues.

Best Answer
0 Votes