elapsedDistance in a vivoactive app..

So, I have an app where I'm recording a session, and in that app, I want to display the distace so far. So he's what I do. It works fine in the simulator, but I get a CIQ_LOG.txt pointing at the line where I try to use elapsedDistance. Any ideas?? (I threw in the "has" lines just in case!)
if(Activity has :getActivityInfo)
{
var actInfo=Activity.getActivityInfo();
if(actInfo!=null && actInfo has :elapsedDistance)
{
var dist="?";
dist=actInfo.elapsedDistance.format("%0.2f");
}
}
  • Former Member
    Former Member over 10 years ago
    You shouldn't need to check if the info object has elapsedDistance because there aren't any versions of the SDK that did not have that, or any products that don't support it. You do need to null check elapsedDistance. (I think you can probably get away with not null checking actInfo, but I'm not certain there.)

    If there is not a session started yet, there won't be any elapsed distance, and it is probably null.
  • I actually do have a session started, and check for that before it gets to the code above. Why would elapsedDistance ever be null if a session is being recorded. "0" I can see, but null?

    update: That was it. "elapsedDistance" starts out as null. It seems that it should be zero, but if there is a reason for "null", this probably should be noted in the documentation for the method.
  • Former Member
    Former Member over 10 years ago
    Has the session been started, or just created?

    ConnectIQ isn't really doing anything with the distance data, so I don't think the behavior will change. We read the distance directly from our internal FIT API, and if it says the distance is invalid, we set the ConnectIQ value to null.
  • I check for "isRecording" before I get to this code. It's recording at the time .

    " if( ( session != null ) && session.isRecording() ) {"

    It's non-null fairly quickly after this, and I can display the proper distance.
  • Former Member
    Former Member over 10 years ago
    I'll ask the keepers of our FIT API why distance is still briefly invalid after the timer has been started. It might be something they can modify, but you'll have to keep the null check around for now.

    Edit: It doesn't sound like this behavior will get changed. I'll look at hiding it at the ConnectIQ level.
  • If it can't be hidden (or until it it), a note in the documentation for elapsedDistance would be good.