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 

 

 

 

  • Activity.getActivityInfo().currentLocation has value only during activity with gps and a few moments after finishing it. so when you returning to WF you can use it if it isn't null and you have to save it if you want to use it in the future

  • After you do an activity with GPS, Activity.Info.currentLocation will be valid for maybe an hour, so if you return the the watch face soon after an activity, you'll get your last GPS location.  And yes, you do want to save it for use when you see a null.  The f5x and S60 are odd (dual core devices) in that you'll only get it when you are in the watch face picker, not running the watch face normally.

    Save it in storage so the background service has access, as it's what's doing the makeWebRequest to get the data. 

  • Thanks jim and psx.

    So if I understand this,  obtaining the positron in a widget (my forecast app) is not enough, it has to be an activity?

    Also and I am guessing the descent is also a f5x type watch, as i have never been able to get a position via either method even after activity. 

    if this is correct then even an activity position is not picked up unless you exit the watch face and re-select it? That sounds weird and frankly dysfunctional. Surely the is a way to obtain this key information.

  • No, the f5x is part of the original f5 series.  Pre Music, but had maps.

    It's really not that bad, and I've had WFs like this for a long time.  You only have to do it onces (and save it!), and if you've done n activity earlier in the day than you install your WF, it might already have the location.

    Even with your widget, you can run into issues if you start GPS but aren't in a good location for GPS where the widget can time out before there is a fix.  I also cache the location in mine, but also have an option to start GPS if you are in a different location.  You probably don't want to start GPS each time the glance for your widget is showing or again when you go to full screen.

  • Its for a Descent Mk2S if it helps

    Also and I am guessing the descent is also a f5x type watch, as i have never been able to get a position via either method even after activity. 

    I think the Fenix 6S Pro is closest to the Descent Mk2S, based on release dates, the fact that DC Rainmaker and readers said that Descent Mk2-series watches are based on Fenix 6-series watches, broad features (e.g. music), screen resolution (240 x 240), and the fonts used in the simulator (e.g. "FNT_FENIX6S_CDPG_ROBOTO_13B").

    See compiler.json and simulator.json in the respective device folders of the SDK (fenix6spro and descentmk2s).

  • Thanks Jim,

    Obviously the ideal would be for the watch face to keep track of position, but I understand that has consequences.

    I would think that a call to Position.getInfo().position or something similar to retrieve the last obtained position (however obtained) would be valuable...

    The next best was some quick way to reset the position when moving. Starting an activity seems a clumsy way to do that but I guess that's all that's available. I will probably go to the trouble of creating an activity to make this as painless as possible.

    Thanks for your valuable help. It is clear from reading the forums that you are helping lots of poor souls like myself.

    Best Regards

    Al 

  • Thanks FlowState,

    I did manage to get Activity.Info.currentLocation to give me a location shortly after an activity (I don't much use them). 

    Best Regards

    Al 

  • GPS is expensive battery wise, so it's only on when needed.  Even if GPS was on once every 30 minutes, it would be a drain, and consider there would be many times it would be hard to get a lock - you are inside, etc.

    From a watch face, you can't turn on GPS - Position isn't available in the WF.

    Using Activity.Info.currentLocation can just be a one time thing - If you have a location, save it in Storage for when you don't.  Starting an Activity, stopping it after a lock, and returning to the WF only takes a couple minutes, and you can get y with only doing it once.

  • In case this is useful for anyone else, I have found the best solution (for me) is to check for Activity.Info.currentLocation as above, but if null to check Weather.getCurrentConditions.observationLocationPosition roughly as below

    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();
                }

  • What you see in Activity.Info goes stale after a bit of time.  If you start an activity that uses GPS, then after a lock, you go back to the WF, it should be valid.  If it is valid, save it in Application.Storage, and use it  when you see currentLocation is null.  While you can use Toybox.Weather, that only works on devices with weather, and not all 3.2 devices do, and none before 3.2.  Using currentLocation will work on all devices with GPS.