GPS does not update in watch app.

I'm trying to create a small app that need to get the postion in real time. It's work on the simulator but when i try it on my watch, the position module does not work : the Position.getInfo() command just give me a position that dates from my last garmin running activity and note the current one.

I use Position.getInfo()  in the onUpdate() function, should I do otherwise?

  • In a device app, you need to enable/turn on GPS. The sim doesn't need that.

    Use:

    Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
    The onPosition call back is passed the data so you don't need to call getInfo()
  • class MyView extends WatchUi.View{
    
        public var actualLoc as Lang.Array<Lang.Double>?;
    
        public function  initialize(){}
    
        public function onUpdate(dc as Dc) as Void{
            actualLoc=Position.getInfo().position.toRadians();
        }
    }

    My code looks like that

  • class MyView extends WatchUi.View{
    
        public var actualLoc as Lang.Array<Lang.Double>?;
        hidden const timer = new Toybox.Timer.Timer();
        
        public function  initialize(){
        self.timer.start(method(:onTimerUpdate), 100, true);
        }
        
        public function onTimerUpdate(info as Postion.Info){WatchUi.requestUpdate();}
    
        public function onUpdate(dc as Dc) as Void{
            actualLoc=Position.getInfo().position.toRadians();
        }
    }

    More like that in fact, it may be important

  • But you aren't turning on GPS on the device (enableLocationEvents).  See the recordsample in the SDK It starts GPS, and allows recording an activity

    BTW, updating the screen every 100ms will really impact the battery.  The location changes about every second, so you're updating the screen 10 times each time you have a new location.

  • Ok thanks i will try it

  • Does my code need to looks like that:

    class MyView extends WatchUi.View{
    
        public var actualLoc as Lang.Array<Lang.Double>?;
        hidden const timer = new Toybox.Timer.Timer();
        
        public function  initialize(){
        self.timer.start(method(:onTimerUpdate), 1000, true);
        Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
        }
        
        public function onPosition(info as Postion.Info) as Void{
            actualLoc=info.position.toRadians();
        }
        
        public function onTimerUpdate(){WatchUi.requestUpdate();}
    
        public function onUpdate(dc as Dc) as Void{
            
        }
    }

    I just realized that I had put a Postion.Info argument in my onTimerUpdate function in my example code, it was obviously an error Slight smile

    This new version does not looks to works, even in the simulator, did I do something wrong?

  • couple things.  You can actually do away with the timer, and just call watchUi.requestUpdate() in your onPosition function. (it gets called every second)  Also while you start with actualLoc as an Arry, you and then setting it to a single location (line 12)

    Also, your onUpdate function isn't doing anything so you'll see nothing on the screen.

    With GPS, it can take a minute or more to get good data so you probably want to check info.accuracy

  • .toRadians() return an array of Double no? So actualLoc must be an affay of double right?

    The onUpdate function isn't doing anything because this is not my real code, just à simplified version with just the necessary to explain my problem. I can send the real one if you want but it's pretty long and comments are in french (because i'm french:) )

     In the simulator GPS data should be Goodyear immeditely no?

  • Your are right. the toRadians() returns an array.  I was thinking you wanted an array of locations.

    When you use  the sim and select the "activity data" and data simulation. it actually starts in Olathe Kansas (the Garmin HQ)

  • class MyView extends WatchUi.View{
    
        public var actualLoc as Lang.Array<Lang.Double>?;
        
        public function  initialize(){
        Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
        }
        
        public function onPosition(info as Postion.Info) as Void{
            actualLoc=info.position.toRadians();
            WatchUi.requestUpdate();
        }
        
    
        public function onUpdate(dc as Dc) as Void{
            
        }
    }

    now my code looks more like that. it does not works, the actualLoc variable stay null