CurrentHeading

Hi,

I am developing a data field and I want to display a compas; I guess that I have to use info.currentHeading which is referenced in radians so to convert in degrees I have formula 1 radian = 57 * degrees.

Once I have degrees from 0 to 360 I can know if it's N, E, SE, etc.... but I am getting numbers in negative??? Why?

How to solve it?

Thanks in advance,

Oriol

  • You actually see -180 to +180 and not 0-359, with 0 being North.

  • Thank you,

    If 0 North then S is 180 & -180, E is 90 and W is -90? NE 45, SE 135 etc..?

  • If you want a standard heading from 0 to 360, you can use the following code snippet:

    function radiansToDegrees(value) {
        value = Math.toDegrees(value);
        if (value < 0)
        {
            value += 360;
        }
        return value;
    }
    

  • Thank you!!

    This is how it looks my snippet Slight smile

    if ((info has :currentHeading) && (info.currentHeading != null)) { 
      vCurrentHeading = Math.toDegrees(info.currentHeading); // Convert 1 radian to degree.
      if (vCurrentHeading < 0) { vCurrentHeading += 360; }
    } else { vCurrentHeading = 0; } // North

  • No worries!

    And the reason you get negative numbers is because currentHeading ranges from -pi to +pi.

  • There is an issue with currentHeading(), as and I have observed. Where currentHeading() goes wonky now and then on devices with a compass, and it randomly diverges from the true heading. Better to use "track()". It appears that track() uses GPS deltas, but currentHeading() can switch between GPS deltas and the internal compass sensor (even when moving), which may be uncalibrated or affected by surroundings.

  • It's always been the case that you are moving at a slow speed (or stopped) it will show the compass heading and not one based on GPS.  If I recall, the cutoff was around 2mph.

    You'll find references to "Best source" for things like this in old posts in the forums

  • I asked my user and he was riding along steady at 30k/hr when the currentHeading() diverged dramatically from the Garmin Map's North indicator. So there is something else going on. Maybe the GPS signal dropped out for a moment? Not sure what is happening on the EDGE 1030Plus

  • - This topic is over two years old and it's not really an "open-ended discussion topic" (like some long-standing feature request or a discussion thread about an old app that's still being used.) Obviously you can post here if you want, but idk if OP is still interested in the topic. (For other people, your current topic has the same information.)

    - OP specifically said they want to display a "compass", so I'm not sure if ActivityInfo.track is the best solution here. As you said, it's only based on GPS data, but personally I want my compass to work even if I'm standing still (or especially if I'm standing still)

    - ActivityInfo.track is only available for multisport watches / cycling computers, whereas currentHeading is theoretically supported by all devices (although ofc some devices lack a compass, so for those devices you'd always get GPS heading.) ActivityInfo.track seems like one of those CIQ features that's intended to be only available for devices that support navigation (with saved courses), but for some reason, new-ish non-multisport devices which *do* support navigation -- like Forerunner 255/265 -- are excluded.

  • Makes sense. In the simulator, track doesn't even work. Always returns ZERO, whereas currentHeading does work. On my real EDGE 1030 device (no compass), Heading and Track are always exactly identical when moving. But when stopped, currentHeading reports null whereas Track retains the last value. I imagine on an EDGE 1030plus with a compass, the currentHeading would be based on the compass sensor.