Sun rise / sunset

Could some kind person provide an actual working example of how to get sunrise/sunset info for a watch face? TIA!
  • If is some problem with first barrel file so try this one. I have compiled it again with the last SDK
  • what is a barrel file and how do i use it? ta
  • See the 2.4.1 programmer's guide. Monkey Barrels are a new way to share code.
  • Monkey Barrel dependencies were detected during Jungle file processing. Barrels are not supported by device: fr935.
  • When you do a run in the sim, set the Target SDK level to 2.4.x
  • what i was after was code to determine sunset and sunrise that would work on all devices and sdk versions
  • Former Member
    Former Member over 7 years ago
    what i was after was code to determine sunset and sunrise that would work on all devices and sdk versions

    Is that not provided in the barrel that Stanislav.Bures posted? It looks like it works to me.
  • but what about users of the 920XT for example, barrels are not supported
  • Hi there,

    i just got a Forerunner 235 and playing around with the SDK to create my own watch face.
    While searching around for a way to display the sunrise/sunset, i stumpled upon this forum and saw the SunCalc implementation from Backslashhh.

    First of all thank you very much for your open source code for your widget.

    However, i got some problems using the SunCalc class to calculate the sunrise/sunset. Maybe somebody can help out?

    Currently i use this code:

    var sunset = "n/a";
    var info = Activity.getActivityInfo();
    var pos = info.currentLocation;
    if (pos != null and (Time.today().greaterThan(sunsetCheck) or sunset == "n/a")) {
    var sc = new SunCalc();
    var loc = pos.toRadians();
    var sunset_moment = sc.calculate(new Time.Moment(Time.now().value()), loc, SUNSET);
    sunset = sc.momentToString(sunset_moment, Sys.getDeviceSettings().is24Hour);
    sunsetCheck = Time.today();
    }


    I only want to calculate the sunrise/sunset once a day, so i try to detect it with the if-clause. (By the way: is there a way to set the position while testing? I didn't find anything in the eclipse plugin about it and copying the compiled watch face to my Forerunner 235 for testing purposes isn't the best workaround IMO).

    Unfortunalety i get not the correct time for sunset/sunrise (e.g. sunset for today calculated is 18:59 and google says it's 16:53).
    Does anybody got the same problem or can tell my why the calculation isn't working properly?

    TIA:o
  • This is something where you want to look into using the object store. In the case of "pos", that will be null if GPS hasn't been used in a while, but what you can do is if it's not null, save it to the object store. Then in the case when it is null, use the info from the object store. (you'll have a fall back after the first time it's valid)

    And for tracking the "only run once a day", that's also something for the object store. When you calculate rise/set, save those time as well as the date in the object store, and when your app starts, load those values, and if the date is still the same, no need to calculate - just use the saved times. You'll want to add a check for midnight, as the date will change (maybe just null out the saved date so things get recalculated.)

    With your "sunsetCheck", you'll lose that if you go to the widget loop or an app and return to the watchface if you don't use the object store, and you'll recalculate each time to return to the watchface.

    As far as the difference in time, are you sure you're using your location? Are you seeing this in the sim or on the watch itself? With "simulate Data" in the sim, your using Kansas as a location.