getSunset() Function

the getSunset() function is part of the Weather library.

As we know, it is trivial to calculate sunrise and sunset from just GPS coordinates and time. Since Garmin decided to bundle this function in Weather, does that mean we can only count on getSunset() to return a non-null value if you have your smartphone paired with your device AND have Garmin Connect running? That would be unfortunate.

Also, it is curious that this function requires a time moment. You can always pass it Time.now(). So at 9am this tells me that Sunset is at 19:34:06. So then I enter THAT time and run it again. Then it returns 19:34:22. LOL. If I really care about it down to the second. If I wanted millisecond precision, I'd have to run it maybe 6 or 7 times to zero in. Silly, but fun to think about.

  • What are you using for location in the call?  Same location that has sunset at 19:34.06?  If the locations are different, sunset will be different

  • yes - naturally... use "currentLocation".... so at 9am, right here, right now, the projected sunset is X. But that isn't accurate because later in the day (and/or in a different location) the actual sunset will be different. So this is a calculation you'd have to run over the course of your activity as you move and as you get closer to actual sunset.

    My point was.... just a silly algorithmic quirk... to actually estimate the accurate sunset at location X and current time Y, you'd have to run the function multiple times using the better and better estimate of sunset as the time parameter LOL

  • As we know, it is trivial to calculate sunrise and sunset from just GPS coordinates and time. Since Garmin decided to bundle this function in Weather, does that mean we can only count on getSunset() to return a non-null value if you have your smartphone paired with your device AND have Garmin Connect running? That would be unfortunate.

    I doubt it but you can always test it on your device.

    If I really care about it down to the second. If I wanted millisecond precision, I'd have to run it maybe 6 or 7 times to zero in.
    to actually estimate the accurate sunset at location X and current time Y, you'd have to run the function multiple times

    Not to state the obvious, but I think you're assuming a level of accuracy and precision that doesn't exist and isn't practical. As you said yourself, it's an estimate.

    There's probably a reason that weather sites/apps, timeanddate.com and various sunrise/sunset calculators only report sunrise/sunset to the nearest minute.

  • The problem is more in the definition of sunset. Is it when the orb of the sun first touches the horizon or at the time of the green flash as it disappears? The math for calculating the time of sunset for any position on earth is easy enough to get to the second. I have some functions that calculate it all in my watch face so it doesn't depend on the phone or the internet. It's the atmospheric refraction which depends on the weather that can throw everything off by a few minutes. A quick search of the internet reveals that not everyone agrees on what "average" refraction time is, so the answer is that there is no answer. https://skyandtelescope.org/astronomy-news/we-dont-really-know-when-the-sun-rises/

  • The issue with a watch face is actually the location.  You can hard code it with app settings (and worry about float vs doubles) or you can use the location from the last time GPS was used (which can be different than where you currently are), or in Weather, you can try observationLocationPosition, which is where your phone was up to an hour ago.  A watch face can't start GPS and get your location at any given time.

    Any method I mentioned can easily lead to an incorrect (off by seconds) value

  • You're right, if you really need to know to the second then you would need to have an app that can access GPS and be at the place you will be at sunset. If you want to know about when sunset is and you are in the area of the last time it had a position then the watch face will be close enough. You would need to move about 15 miles (24 km) to change the time by a minute. Which begs the question, if you don't use an app on the watch to get position, how often does it get position and from where? Can it get a position from the phone at some interval, or does the watch have to get it itself?

  • With Garmin Weather is uses the phones location to get the data.  Today, in oberservationLocationPosition looks to be the phone's location (last I checked), but observationLocationName is where the weather station that the data came from is located, which can be very different.  Plus that cat can be up to an hour old, even if you have your phone in hand.

    You can start an activity that uses GPS, wait for a fix, and when you return to the watch faces, use Activity.Info.currentLocation on most devices (not the fenix5x)

  • We discussed and Garmin confirmed that the Weather observation location erroneously returns the cellphone location :-( I hope they fix that. But maybe WX stations don’t report their coordinators?

    the main reason to grab Sunset/Sunrise throughout the activity (not just at initialization) is if the user crosses time zones.

  • I'm using Position.Location, but I don't know how it relates to Activity.Info.currentLocation. Probably the same, do you know? If so or at least close enough then I could use it instead of Position.Location and have one less object taking up space. I tried using Activity.Info. Bearing in place of compass but that didn't work as well as I would have liked.

  • I've always used Activity.Info.  I seem to recall that Position can't be used on older devices with a watch face..