Calculating or obtaining distance

I am trying to calculate a distance on a data field. I am trying in different ways, bu I don't seem to be able to solve it.

I have a couple of issues:

1. When I run simulation, my activity info elapsedDistance value does not change. If I try with a .fit file, it is the same. It is either 0 or a fixed value.
Is it a simulator issue, or elapsedDistance is not reliable?

2. I know this is basic, but I have a calculation function that gives me a distance between two GPS coordinates. i could use it with the activity position, but I cannot figure out how to pass values to another function.

function compute(info) {
startLat = info.startLocation.toDegrees()[0].toString();
startLon = info.startLocation.toDegrees()[1].toString();


if(info has :currentLocation){
if(info.currentLocation != null){
lat = info.currentLocation.toDegrees()[0].toString();
lon = info.currentLocation.toDegrees()[1].toString();
}
}
speedGps = info.currentSpeed;
Sys.println("Distance = "+info.elapsedDistance);'


calculateDistance(startLat, startLon, lat, lon);

// get the distance back here.


}

function calculateDistance(startLat, startLon, lat, lon) {

// USE my function and variables here to calculate distance

// How do i send the distance value back?

}





3. I cannot figure out if there is a way to calculate distance using accelerometer data. Do I need to calculate it between points? Can I use the accelerometer in a data field?

Thanks for the help
  • 1) in the sim, make sure you start the activity when playing back a file or simulating data. You must "start" the activity. You can click on the "start" button for the device in the sim, or use Data Fields>Timer>start

    2) in your function, just return the distance in the form you want - meters, feet, a sting etc.

    return distance;
    at the end of computeDistance();

    and then in compute,
    var cDistance=calculateDistance(startLat,startLon,lat,lon);

    3) Not sure why you'd be using the accelerometer for distance. Is it because of question #1? You can get data for it in a background process in a DF, but only every 5 minutes.
  • Thanks Jim. 1-2 are perfect .as for 3, I find the GPS signal not always reliable in the environment where the data field is used. So I was planning to use the accelerometer to compensate .
  • For #3, as I said the background runs at most every 5 minutes, and each time it runs, it can run for a max of 30 second.

    You'll also need to think about how to integrate the non GPS distance data in the .fit file. You can't modify the normal distance field, so it would be a fitContrib field and separate.

    You can get distance without GPS being enabled - it uses steps and your stride length, or in some cases, cadence from something like a foot pod.