Pedometer Plugin (How to Display Distance Covered by User)

Pedometer Plugin (How to Display Distance Covered by User)

  

Hello,


While using the Pedometer Plugin, the Steps are increasing and the data is being displayed on the screen, I want to display the distance covered by the user,  but the distance variable shows undefined on the screen. Kindly help to rectify the error, It will be much appreciated.

JavaScript Code :

var successHandler = function (pedometerData) {

    document.getElementById($parameters.Steps_InputId).innerHTML = pedometerData.numberOfSteps;
    document.getElementById($parameters.Distance_InputId).innerHTML = pedometerData.distance;

};

var onError = function() {
    alert('error');
}

pedometer.startPedometerUpdates(successHandler, onError);

Hi Jasman,

You might be missing the $resolve(); call in your javascript code.

You can inspect the Barcode Plugin for example and check how they're doing it. 


Also there's some documentation about Asynchronous JavaScript Code here, that's worth reading.

Cheers,
Miguel


Hey Miguel,


I tried adding resolve to the code but it still not calculating or displaying the distance covered by the user.(It comes undefined when i click Walk ) Could you further help to solve it. Thanks. Your Help is Appreciated!!


Code :


var successHandler = function (pedometerData) {

    // pedometerData.startDate; -> ms since 1970

    // pedometerData.endDate; -> ms since 1970

    document.getElementById($parameters.Steps_InputId).innerHTML = pedometerData.numberOfSteps;

    document.getElementById($parameters.Distance_InputId).innerHTML = pedometerData.distance;

    $resolve();

    // pedometerData.floorsAscended;

    // pedometerData.floorsDescended;



};


var onError = function() {

    alert('error');

    $resolve();


}


pedometer.startPedometerUpdates(successHandler, onError);

Regards,

Jasman