Get speed

Former Member
Former Member
Hello,

i'm writing a Watch App and i want to read the speed.

I have a function where i read the infos

var info = Sensor.getInfo();

if (info has :speed && info.speed != null) {
velocita=info.speed;
}

When i run the app in the simulator (menu Simulation -> FIT data -> Simulate data) the speed change correctly.

I have uploaded the app e load on the watch, but the speed is alway 0.

What i need to do before, to read the speed?

thanks in advance,

Federico
community.garmin.com/.../1405822.png
  • In your app, are you recording? You won't see speed unless you are. With Simulate Data, you are feeding it data as if you were recording, so you'll see things change in the sim.

    If your are using Sensor, don't forget to use setEnabledSensors() for the ones you want, and if you are recording, you may want to use Activity.Info instead of Sensors for this.

    To see what I'm saying about recording start someing like the native "run" app and set a DF for speed. It will be 0 until you start recording (and are moving)


  • Former Member
    Former Member over 6 years ago
    In your app, are you recording? You won't see speed unless you are.


    I'm pretty certain this is not true. Speed is not a thing that is specific to a recording. This would be true of something like distance.

    Probably your second comment about enabling sensors is the issue here. You will need to enable GPS or a sensor that provides speed to get speed on device.
  • Yes Brian, you're right! I was on my first cup of Coffee! :)
  • Former Member
    Former Member over 6 years ago
    thank you Jim and Brian.

    i enable GPS

    Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));

    and then get infos

    var info = Sensor.getInfo();
    if (info has :speed && info.speed != null) {
    velocita=info.speed;
    }

    i will try it.

    I have intercept the onPosition method too.
    This to calculate di distance between two points of GPS

    function setPosition(info)
    {
    var myLocationD = info.position.toDegrees();

    // System.println("Longitude: " + myLocationD[1]); // e.g -94.800953
    // System.println("Latitude: " + myLocationD[0]); // e.g. 38.856147

    if(null!=previousD){

    var distanza = Math.asin(
    Math.sin(previousD[0]) * Math.sin(myLocationD[0]) +
    Math.cos(previousD[0]) * Math.cos(myLocationD[0]) *
    Math.cos(previousD[1]-myLocationD[1])) * 6372.795477598;
    System.println(distanza);
    }
    previousD = myLocationD;
    }

    but the result is not good

    Federico
  • You'll want to check the accuracy of GPS, as based on a few things, it can take a while to get a fix.

    You can do that in onPosition(). Until you get a fix and are then moving, speed could remain at 0.

    Update: I just ran a test with one of my (recording) apps with GPS, and after I got a good fix, speed remained 0 for maybe 20 seconds after I started moving (this was from Activity.Info). I'll see what speed looks in Sensor with another app that uses GPS but doesn't record and update again.

    Update2: Without recording, and with getting the speed from Sensor, I'm getting a valid speed, but like the recording app, I wait for a good GPS fix, and it's 10-20 seconds after that there is a speed. Brian was correct. No recording needed with GPS active. Brian, you caught me! :)
  • Former Member
    Former Member over 6 years ago
    thank you Jim,

    I do not need such accurate accuracy

    but I have a doubt: if not from the GPS, how is the speed calculated?

    It seemed obvious to me that the calculation was on the GPS coordinates.

    If not, should be interesting to know how.

    Federico

    You'll want to check the accuracy of GPS, as based on a few things, it can take a while to get a fix.

    You can do that in onPosition(). Until you get a fix and are then moving, speed could remain at 0.

    Update: I just ran a test with one of my (recording) apps with GPS, and after I got a good fix, speed remained 0 for maybe 20 seconds after I started moving (this was from Activity.Info). I'll see what speed looks in Senor with another app that uses GPS but doesn't record and update again.


  • Try you app, but maybe display the accuracy on the screen to see when you get a good fix. If you don't have a good fix, it will keep trying to get one while you're moving.

    What device are you using?
  • Former Member
    Former Member over 6 years ago
    good morning Jim,

    ok, i wil try but i must wait (?) to upload a new IQ versione.
    i have already uploaded one and i cannot upload another with the same IQ.

    The device that i use is a Vivoactive 3.

    federico

    Try you app, but maybe display the accuracy on the screen to see when you get a good fix. If you don't have a good fix, it will keep trying to get one while you're moving.

    What device are you using?


  • Former Member
    Former Member over 6 years ago
    hi Jim,

    i have try the app on my device (uploading the prg).

    the speed work but i don't understand what the device measures.

    this morning on the motorbike i'm at 120 km/h and the app marked 35.

    i think the best way should be to use the GPS.

    Federico

    Try you app, but maybe display the accuracy on the screen to see when you get a good fix. If you don't have a good fix, it will keep trying to get one while you're moving.

    What device are you using?


  • See the API documentation in the SDK. You see the speed in meters per second.

    35x60x60=126000 meters/hour=126km/h