Average Speed in last lap

Former Member
Former Member
Hi,
I make an app, when I launch an activity (through ActivityRecording.createSession).

I made a lap through mysession.addLap()

I get the Info through the Activity.getActivityInfo();

and I get the averageSpeed through info.averageSpeed.

But what I wanted to have is the averageSpeed from the last lap, and not from the start , and I don't find it ...
Do I need to calculate myself ? Because, I don't see either the distance done since the last lap ...

And another question : How to enable the GPS in an app ; because it seems that my app didn't search the GPS.

Thanks for your help.

Rgds
  • All Lap information needs to be calculated manually by you.
    Since this is an APP and not a datafield, I am unsure if you can use the onTimerLap (https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/WatchUi/DataField.html) based on that, seems like you can't

    To ask for GPs, you need to request it.

    https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Position.html#enableLocationEvents-instance_method
  • As you have an app, and are doing the lapmarks yourself (the call to addLap()), you know exactly when a lap occurs and you need to save off time and distance when you call addLap() and use that to calculate speed yourself. For example, if the lap takes 10 minutes and you went .5 miles, your avg speed is 3mph.

    As far as GPS, in an app you need to start it by calling enableLocationEvents() before you start recording.
  • Former Member
    Former Member over 8 years ago
    Ok thanks, I'll do the calculation.

    for the GPS, I was doing :

    Position.enableLocationEvents( Position.LOCATION_CONTINUOUS, method( :onPosition ) );
    mSession = ActivityRecording.createSession({:sport=>ActivityRecording.SPORT_RUNNING, :name=>"Test"});



    I'll try :

    mSession = ActivityRecording.createSession({:sport=>ActivityRecording.SPORT_RUNNING, :name=>"Test"});
    //enable after.
    Position.enableLocationEvents( Position.LOCATION_CONTINUOUS, method( :onPosition ) );



    If this didn't work, I'll ask it again. Thanks
  • I enable GPS first (the first bit of code you posted), but don't create/start the session until I've gotten a position (by way of "onPosition()"). It could be you're doing the create/start too soon. Are you doing the start right after the create?
  • Former Member
    Former Member over 8 years ago
    Hi again,

    it seems that the enableLocationEvents works, but I don't have the indication that the GPS is found (like in the native application : you have a red circle, next orange , and finally green to confirm that the GPS is acquired).

    how to do it ?

    Thx
  • This is something else you have to do yourself in an app. (A CIQ app doesn't have access to the same type of GPS info as the native apps seem to have, and what happens varies by device)

    Here's what I do:
    When starting, I display a message that says "waiting for GPS".

    In onPostition(), I check for an accuracy of "usable" or above, and if so, i set a flag that I have GPS, and the message I display changes to "press start to begin"

    In the behaviour delegate for KEY_START/KEY_ENTER, I check the GPS flag, and if session is still null, I create and start the session. If the session isn't null, I stop the recording and put up a "Resume/save/discard" menu. (this allows doing a manual "pause" in the app)
  • Former Member
    Former Member over 8 years ago
    Ok, thanks