Location in the watch face after no GPS activity

Hello all,

I have question which has been probably discussed many times but no solution found. I want to use location in my watch face for calculating sunset/sunrise. I found this code

if (Acty.getActivityInfo().currentLocation != null) {
var loc = Acty.getActivityInfo().currentLocation.toRadians();
}


which is working quite well. But if I start activity without GPS (pool swimming, strength training), the location is not available and I need to start any GPS activity for new position. I saw another watch faces where sunset/sunrise is in use and visible after pool swimming, strength training. Thanks for any hint!
  • The key here, is that currentLocation won't always be available. Even if your last activity used GPS, it will "go stale" after a certain amount of time.

    So what you do, is when you get a valid one, you save it to the Object Store. Then, if currentLocation is not available, you use the value from the Object Store (Application.Settings is also available in 2.4.x and above) . Once you have a valid location, you'll have a valid location after that.
  • Thanks for your quick answer! This really helps! Example how to do it can find everyone here.
    // Set an Object Store value Application.getApp().setProperty("myObjectStoreItem", myObjectStoreItem); // Get an Object Store value var myObjectStoreItem = Application.getApp().getProperty("myObjectStoreItem");

    Maybe it helps someone.