Getting GPS information for a watchface on Fenix 5/FR935

Hi,

I transfer a watchface from the F3 to the new device platform. My watchface supports sunrise/sunset calculation and relys on

Activity.getActivityInfo().currentLocation

This worked rock solid on my F3. Using this code on a F5 leads sometimes to a "null" value. Is there a more stable method to get to the current coordinates? If not I would store the information temporarily in the object store....
  • It's only valid for a time after you save/discard an activity on most watches and even a bit harder to get on the f5x (see https://forums.garmin.com/showthread.php?376075-Fenix-5x-and-sunrise-sunset-here-s-how-to-do-it!).

    On the others than the f5x, start a GPS recording, then discard it after it's got a GPS fix. At that point you should get the lat/lon in currectLocation.

    At when you do get it, you want to save lat/lon so it's available as a fallback for when currectLocation is null. (save it in the Object Store)
  • Jim, a user who owns a F5X showed my a picture of my watchface where also the altitude is not working. I grab the altitude in this way:

    var altitude = Activity.getActivityInfo().altitude;


    but the altitude is null on the F5X and my watchface shows "---". Saying this on all my other watch faces the altitude is changing instantly although the alt from the activity is static.

    To be honest I don't understand the behavior of the F5X nor the behavior of the other watches. How do you grab altitude for a watch face? The sensor class is no option since it is not accessible from a watchface.
  • When I do elevation in a watchface, I just use the newest sample from SensorHistory.getElevationHistory()

    I don't think I've tries it on a f5x yet.
  • Arrrgh, I didn't use this in the past since all my supported watches are below CIQ2.1.0. I searched the API for altitude and did not found the elevationHistory. Thanks for sharing. This is really an easy way.
  • I just tried one of my WFs that does use SH for this on an f5x and appears to work just fine....
  • Hi Jim,

    I am not sure whether I use the sensor history information right. I typically have an elevation here around 300 m. I played back a fit file and reloaded the simulator. Nevertheless, I get an altitude of 1371 m (4500 ft). I used following line of code to grab the elevation:

    var altitude = Shi.getElevationHistory( { :duration=>1, :order=>Shi.ORDER_NEWEST_FIRST } ).next().data;


    where Shi points to Toybox.SensorHistory

    Am I doing that right?
  • What does the widget for elevation show? With getElevationHistory you're looking at that data and not anything from your last activity... Use the widget to compare..

    I see 1260 ft with getElevationHistory(), which happens to be the elevation of my house (on a f5x)... :)

    With SH, I generally default everything, and just use the 1st sample.
  • With SH, I generally default everything, and just use the 1st sample.


    Ok, that's exactly what I want to do with my Watchface. I am wondering if getting the entire history is necessary for that (therefore the duration=1). But you probably are right, that only the first pointer to the chained list will be retrieved. Saying this, how do you call the first item of the the list? Can you just post that line of code? Thanks
  • With this call:

    elev=getSample(SH.getElevationHistory({}));

    and this function:
    function getSample(iter) {
    if(iter!=null) {
    var sample=iter.next();
    return sample.data;
    } else {return null;}
    }

    You get the newest sample