Altitude data on EDGE Datafield

Hi,

I am trying to develop a datfield for EDGE device.... The idea is to show the altitude data but when I displayed on simulation it's showing wrong number. I check simulation setting "GPS position" but the new position is showing bad number.

Attached my code to display this number.

// ALTITUDE metric ++++ The altitude above mean sea level in meters (m) // Toybox.Lang.Float
        if( info has :altitude ) {
            if( info.altitude != null ) {
            var deviceSettings = System.getDeviceSettings();
            if ( deviceSettings.elevationUnits == 0 )
                { vAltitude = Position.getInfo().altitude.abs(); if ( vInitialAltitude == 0 ) { vInitialAltitude = vAltitude; } } // UNIT_METRIC = 0
            else { vAltitude = (Position.getInfo().altitude.abs() ) * 3.28; if ( vInitialAltitude == 0 ) { vInitialAltitude = vAltitude; } } // UNIT_STATE = 0
            } else { vAltitude = 0.0f; }}

Sys.println("Value vAltitude : " + vAltitude);   

What is wrong on this code?

Is there another way to get this number?

Thanks in advance,

  • Hi there, I haven't used the Position module before - and it looks like you're mixing your module usage there "info" and "position".  If you're just after simple altitude just use info.altitude (this is what I use in my apps to calculate gradient for cycling).  If you want to test this, run your datafield against an activity (ie, run it with a FIT file that has recoded a GPS track).

  • info (which is passed in compute) is all you need.

    info.altitude is the altitude.  No need to use Position.

    Also, you don't want to use abs() as you could be below sea level