How best to get a GPS location in a watch face

Hi all, 

I have been writing a set of apps for my own use including a weather forecast app and a watch face that has some forecast info. Its for a Descent Mk2S if it helps.

The forecast app calls Position.enableLocationEvents and obtains a lat / lon and stores that and that works fine. 

However the watch face (as I understand it) cannot do that, and nor can it obtain the stored location from the Forecast  app, and everything else I tried seems to have problems.

Activity.getActivityInfo().currentLocation seems to always come back null, and Position.getInfo().position weirdly comes back as lat = 180, lon = 180!. I have enabled the position permission.

I would be very grateful if someone would describe what is needed to make this work. 

I have seen comments by Jim and others to the effect that a recent GPS position is needed, but even immediately after running the forecast app the watch face does not get a usable position.

Thanks for any help 

Al 

 

 

 

  • So what is the best solution to get Lat, Lon? I have used several options, I store the values ​​in the device memory, but still I cannot avoid the problem that the word "Globe" appears next to the city name and I do not have current weather data. I even use the warning that "gps" if the value is null.

    It's only a Fenix ​​6 device for me.

  • Hi Fred,

    I haven't tried to get the city name, I just want the lat / long. to get this in a watch face (Descent Mk2 so similar to Fenix) I do

                if (Toybox has :Weather) {
                    var wcc = Weather.getCurrentConditions();
                    if (wcc != null && wcc.observationLocationPosition != null) {
                        var wll = wcc.observationLocationPosition;
                        lat = wll.toDegrees()[0].toFloat();
                        lng = wll.toDegrees()[1].toFloat();
                        llt = "whr";
                    }
                }
                var curLoc = Activity.getActivityInfo().currentLocation;
                if (curLoc != null) {
                    lat = curLoc.toDegrees()[0].toFloat();
                    lng = curLoc.toDegrees()[1].toFloat();
                    llt = "pos";
                }

  • hi "Globe" is where lat 0 and lon 0 are returned.

    you want to check the GPS accuracy before saving it and unfortunately check for the 0,0, 

    it is a "well known" issue, see the Bug report section.

  • Hi Jim, I have been successfully using this method for a long time, but recently the Activity.getActivityInfo().currentLocation doesn't return null after the validity of last known location is expired! It rather returns some default value via Garmin Connect app, which renders this method unusable, because it rewrites my stored values with the (wrong) default positioning data.

    The only solution is to disconnect the Garmin Connect app from the watch after the GPS lock (after retrieving and saving valid current location), which is obviously not a solution I'm looking for. Is there any other trick how to solve this? (I know about new System 5 possibilities, which I use for new devices, but I need a solution for old devices as well). Thanks for your help in advance!

  • I've pretty much moved away from using a background service in a watch face for this.  I have widgets for two different weather providers, which have their own background services, and on watches with complications, I publish the data when the background runs and subscribe to it in the watch face,  On devices without complications I just always use Toybox.Weather.

  • Thank you very much for your fast response! The problem is, that I want to support even the older devices without a Toybox.Weather implementation (I'm using lat/lon values to compute the sunrise and sunset times).

    Fortunately, I already found a workaround! I check not only if Activity.getActivityInfo().currentLocation returns null, but also in case it returns loc[0] and loc[1] == 0.0 I'm using stored lat/lon values. This should work, except that one specific location on Earth. ;)