Fenix 5x and sunrise/sunset - here's how to do it!

The f5x HW is different with a few things, and one is how a watch face can get lat/lon for sunrise/sunset calculation.
If you have "Contact Developer" messages about your watchfaces and sunrise/sunset, here's something you can reference:

https://forums.garmin.com/showthread.php?376023-quot-HandsFive-quot-Watch-Face-Issues&p=984097#post984097

I explain in the post about what's going on with Activity.info and currentLocation on the f5x, and how to make your watch face run there and display the rise and set.

The key here, is once you have a lat/lon, be sure to save it in the object store so your watchface will have it in the future if a new one isn't available!

Oh, another thing. For things like heart rate, the 3.21 beta or above FW (3.30 is the current production FW) fixes that one!
  • No chance to add the code in the previous post, not even when replacing all "suspicious" characters by standard letters.
    The forum does also not allow attachments or even a link to the file there - so I played around two hours with no success.

    So I'll ty it once again - the code snippet - incredible, in this post, the same link seems to work (while it still can't be added it in the previous post)...

    Jim, I don't have saved anything to the object store (by my own), so the lines seen in the snippet are everything I am doing for handling the geo position. I thought, I would see my home location, because GPS is not active. The returned location is nearby my actual position, I must do a larger move to see what happens.

    If the position will be cached somewhen, I would like to know...
    ...when this will happen (not while doing activities, because my last workout has been far away from the given location)?
    ...how to check if the current location read is from a cache or is "real"?
  • Ok, I wouldn't hardcode a lat/log Here's the flow of how I do it

    get Activity.Info.currentLocation

    if not null
    use that lat/lon
    save that lat/lon to the object store

    if it's null
    get the lat lon from the object store (this may be null if nothing has been saved)

    After this, if there is a lat/lon, calculate sunrise/sunset, else, display something like --:-- for the times

    if you see --:--, solution is to start an activity that uses GPS and get a lock, then discarded the activity. When you go back to the WF, currentLocation will be valid for a while (maybe a hour or more), and it will be available from the object store anytime after that.

    --
    This is also very similar to how I handle lat/lon for things like weather data on a watch face. The request needs lat lon too. In that case, the background process also uses the object store if there's no current data (it tries to read the same keys I use for sunrise/sunset, but the background can't update the ObjectStore if there's new data in currentLocation.)
  • Thanks, I thought it will work more or less like you write, but now my last activity is more than 24 hours back and I did never activated GPS (nor have a connection to GCM) since that...
    My watch still gets a lat/lon combination but I don't know how this can happen...
    ...must go out (but it's quite cold now) to check if the values will change.