Open Source app for Open Weather Map

Hi,

I want to share my Open Source app - Open Weather Widget:

https://apps.garmin.com/en-US/apps/1f3f2d10-ac05-4a9b-a8fa-bdeac8775793

Here is the complete code for it:

https://github.com/desyat/OpenWeatherMapWidget

Specific things that are used in the code:

- Background web requests (OWM API)

- Online web requests

- Open Weather Map API usage example

- Glance view for widgets

It is challenging to reuse the code for 3 different processes in the app (main app, background, and glance view). I attempted to minimize code repetition, but as a result the code got a bit more complicated. Feel free to ask questions or recommend improvements.

Thanks!

  • Actually, it's not that bad.  For example, I have a class called Settings which read my app settings.  In initialize() in both my glance views as well as in the main view, I just create an instance of that class.  No duplicated code.

    And in the case of background data, I save it to Application.Storage in onBackgroundData and the read it in the same two initialize() functions.

    There is much to learn/understand in CIQ which takes some time, and I'll admit, some of the doc is written by people that have known this stuff for a long time and may be a bit sparce at times.  The whole environment was much easier to understand when it came out in 2015.

  • Something else to consider, is how you get the location for the data.  In a watch face, you are stuck with Activity.Info.currentLocation, but in a widget, you can fire up GPS, then cache that for future use.

    In my weather widgets. I also provide a way to do GPS at any time, in the event you've moved a ways since the last time GPS was used.

    This is my OWM widget that does both (as well as the common barrel).And it uses a background service so the data is "fresh" when the widget is opened.  The Menu key fires up GPS.

    https://apps.garmin.com/en-US/apps/6a740b9d-7bba-4ed8-bedd-2cabaef4bdcf

  • No reason to be stuck with Activity.Info.currentLocation. You can use location provided by Garmin Weather, which takes coordinates from the phone and updates them more often then Activity does. It is implemented in my app - take a look. You can also disable using Garmin Weather for location in settings.

    Using real GPS is good too, but of course it is the last resort. My app refreshes weather on Menu press - I might add an option to get GPS location too. I'll update the open source code for everyone to use.

  • The location in GarminWeather location is only valid on some devices, and not the Fenix 5+ which does have_3.2 VM for example.  If you use GPS, it will work on any device

  • Doesn't have to be one or another - you can just get any available location. Garmin Weather works on most recent devices, and it is very easy to check, so it should be attempted before using GPS. 

    Question though - if you start GPS for a single location in your app, will it also update Activity.Info.currentLocation?

  • No, and I don't use LOCATION_ONE_SHOT, but do LOCATION_CONTINUOUS, and then turn off GPS when accuracy is >=QUALITY_POOR.  The reason for this is that with ONE_SHOT . you can get QUALITY_LAST_KNOWN while GPS is starting, so the location isn't actually "current".  Something you won't find in the doc.

    Also, if you do GPS, you save that location in Application.Storage, and when the widget runs again, and there is a saved location, you don't need to fire up GPS unless the user requests it, so you can skip GPS most times.

    With Garmin Weather, that only works on some devices (I've not checked which Edge/GPSMAP devices have it), and there are a whole bunch of users with pre 3.2 devices.

  • Good to know about LOCATION_ONE_SHOT. But does starting GPS update Activity.Info.currentLocation though? I can test it I guess. If it doesn't update Activity.Info.currentLocation, next weather refresh cycle will use old loacation from Activity.Info.currentLocation...

    I can tell that now there are a lot more users that do have devices with Garmin Weather. Most popular Watch Faces with OWM support already use Garmin Weather location - I can tell by the way they are working (updating location right away) Slight smile

  • No, you get the location by way of the callback specified when you enable GPS,  You have to be recording for it to show in Activity.Info.

    You know with Garmin Weather and iOS, the data only requests once an hour (or that was the case last time I checked).  And based on where you are, Garmin weather can be pretty inaccurate, correct?  OWM was used long before Garmin weather came to devices.

    It's really pretty easy to support older devices and non watches if you don't add restrictions you don't need:

    Not sure you're getting where most watchfaces with OWM use the Garmin Weather location. Most cache things like weather data.  

    Original va:

    Edge 530:

  • Like in hockey - I have to skate where the puck is going, not where it is now. You should consider better serving new deviceis, because location from Garmin Weather is hands down better solution for them.

    Using Garmin Weather doesn't mean you can't support older devices - you just have to check if Garmin Weather is supported. Example is available in my Open Source code Slight smile

  • Yes, I was probably the first to post an example of how to check for Garmin Weather at Runtime. And may have been the first to suggest using observationLocationPosition for lat/lon.  In the platform forums, even for newer devices, you'll see a number of cases where devices can't get Garmin Weather, and just show "waiting" in the weather widget.