Access to altitude from datafield

connectiq-sdk-mac-0.2.4/doc/Toybox/Activity/Info.html

The Activity Info object does not seem to provide access to the current altitude, while it does provide current location, heading and total ascent, descent.

the current location object does not provide access to the altitude either.
connectiq-sdk-mac-0.2.4/doc/Toybox/Position/Location.html

So, when implementing a DataField how does one access the altitude info?

I do see altitude provided by the position info object, but this not provided from the DataField object.
connectiq-sdk-mac-0.2.4/doc/Toybox/Position/Info.html
  • We will add the altitude to the Activity.Info class. While Positioning.Location does not have altitude, it is available in Positioning.Info.
  • We will add the altitude to the Activity.Info class.


    That would be excellent, thanks.

    While Positioning.Location does not have altitude, it is available in Positioning.Info.


    As a work around, can a Positioning.Info object be accessed from the DataField.compute() method? Currently it only has an Activity.Info.currentLocation() object.
  • DataFields do not have permission to use the Position module, so you can't use Positioning.Info as a work around. You can use the class below and pass it the info object that is given to compute() for now, and when altitude appears in Activity.INfo you can just remove the temporary class.

    using Toybox.Activity as Activity;
    using Toybox.Math as Math;

    var staticAltitude = 315;

    class InfoWithAltitude {
    var altitude; // in meters
    var startLocation;
    var startTime;
    var elapsedTime;
    var timerTime;
    var elapsedDistance;
    var currentLocationAccuracy;
    var currentLocation;
    var calories;
    var currentSpeed;
    var averageSpeed;
    var maxSpeed;
    var currentPace;
    (:hasPowerSupport)var currentPower;
    (:hasPowerSupport)var averagePower;
    (:hasPowerSupport) var maxPower;
    (:hasBarometerSupport)var totalAscent;
    (:hasBarometerSupport)var totalDescent;
    var currentHeartRate;
    var averageHeartRate;
    var maxHeartRate;
    var currentCadence;
    var averageCadence;
    var maxCadence;
    (:hasSwimSupport) var swimStrokeType;
    (:hasSwimSupport) var swimSwolf;
    (:hasSwimSupport) var swimEfficency;
    (:hasSwimSupport) var averageDistance;
    var currentHeading;

    function initialize(info) {
    var change = Math.rand() % 2;
    if(Math.rand() % 2 == 0) {
    change *= -1;
    }

    staticAltitude += change;

    altitude = staticAltitude;
    startLocation = info.startLocation;
    startTime = info.startTime;
    elapsedTime = info.elapsedTime;
    timerTime = info.timerTime;
    elapsedDistance = info.elapsedDistance;
    currentLocationAccuracy = info.currentLocationAccuracy;
    currentLocation = info.currentLocation;
    calories = info.calories;
    currentSpeed = info.currentSpeed;
    averageSpeed = info.averageSpeed;
    maxSpeed = info.maxSpeed;
    currentPace = info.currentPace;

    currentHeartRate = info.currentHeartRate;
    averageHeartRate = info.averageHeartRate;
    maxHeartRate = info.maxHeartRate;
    currentCadence = info.currentCadence;
    averageCadence = info.averageCadence;
    maxCadence = info.maxCadence;
    currentHeading = info.currentHeading;

    if(:hasSwimSupport) {
    swimStrokeType = info.swimStrokeType;
    swimSwolf = info.swimSwolf;
    swimEfficency = info.swimEfficency;
    averageDistance = info.averageDistance;
    }

    if(:hasPowerSupport) {
    currentPower = info.currentPower;
    averagePower = info.averagePower;
    maxPower = info.maxPower;
    }

    if(:hasBarometerSupport) {
    totalAscent = info.totalAscent;
    totalDescent = info.totalDescent;
    }
    }
    }


    Then in your compute method use this object for now:

    function compute(sdkInfo) {
    // See Activity.Info in the documentation for available information.
    var info = new InfoWithAltitude(sdkInfo);
    }