Heading

Was looking to display "Heading" (direction of movement) in an application. I have tried position/sensor and activity heading/currentHeading attributes but they all display compass readings i.e. watch orientation rather than direction of movement.

Any help would be great.
Thanks,
  • According to the documentation...

    The current true north referenced heading in radians. This value matches heading from the Positioning module. It will provide the direction of travel when moving. When stopped, it will provide compass orientation, if supported by the device.


    If you want to reliably display the heading, you need to grab the current gps position and compare it to the previous gps position, and then calculate the bearing from the first point to the second (using something like this). Of course, if the user is not moving, you need to display something relevant.

    Travis
  • I use a vivoactive, and it doesn't have a HW compass, so my app goes off GPS, and if I stop moving, I do see the direction I get being a bit odd, but knowing that heading on the va requires movement, it's no problem!

    If you have two GPS locations, you can use the code Travis linked to, but for my app, the 8 compass points are fine, so by using a simple compare between the two lat/lon pairs, I can get N,NE,E,SE,S,SW,W,or NW quite easiliy
  • Thanks Jim/Travis for your reply's.

    I was testing on a Fenix3 and it seemed for all 3 Attributes it only gave the compass readings while moving at walking speed.

    Will try using the previous and current GPS position.

    Thanks.
  • I was testing on a Fenix3 and it seemed for all 3 Attributes it only gave the compass readings while moving at walking speed.

    If so, this should be reported as a bug. Either the documentation is incorrect or the implementation is.

    Travis
  • I'll verify this and get it reported if it is a bug. Thanks for the report!
  • On the Fenix 3 the following works for me using info.currentHeading:

    - while standing still it acts as a compass and adjusts based on device orientation;
    - while moving the value acts as a bearing and adjusts based on GPS direction of travel;