Pedometer

This API estimates the number of steps a user is taking and reports real-time updates at each step.

The Pedometer detects individual steps in real-time. When a step is detected, the Pedometer event fires and returns a counter of the total number of steps and two directional components (stepX, stepZ). The directional components (stepX, stepZ) are experimental, and used to distinguish steps forward, backward, left, and right. Pedometer relies on the device's Accelerometer sensor in the user-frame (See Coordinate Frame).

Example

var pedometer = new MotionStack.Pedometer();

pedometer.start(function (e) {
  console.log("step");

  if (e.stepCount === 10) {
    pedometer.stop();
  }
});

Constructor

new MotionStack.Pedometer()

Create a new Pedometer instance object.

Argument Type Description
options Object Options to pass in for the new Pedometer instance (optional)

  • fireOnAnimationFrame {Boolean}
  • Only emit the latest event within requestAnimationFrame intervals.


    Default: false

var pedometer = new MotionStack.Pedometer();

Static Methods

isSupported()

Returns a Boolean describing whether the device has the pedometer capability.

MotionStack.Pedometer.isSupported(); // true or false

Instance Methods

start(callback, [context])

Start receiving pedometer updates.

Argument Type Description
callback Function Callback function that receives an object as an argument

  • function(e)
  • e.stepCount {Number}
    Total number of steps taken since the pedometer instance has been started.
  • e.stepX {Number} (Experimental)
    Experimental property that indicates a side step
    • Equal to pedometer.DIRECTION_LEFT = +1 for a side step to the left.
    • Equal to pedometer.DIRECTION_RIGHT = -1 for a side step to the right.
    • Equal to 0 for a forward or backward step.
  • e.stepZ {Number} (Experimental)
    Experimental property that indicates a forward or backward step
    • Equal to pedometer.DIRECTION_FORWARD = +1 for a forward step.
    • Equal to pedometer.DIRECTION_BACKWARD = -1 for a backward step.
    • Equal to 0 for a side step.
  • e.timeStamp {Number}
    The time in milliseconds when the data is collected
context Object Context in which to invoke the callback (optional).
pedometer.start(function(e) {
  console.log(e.stepCount);
});

stop()

Stop pedometer updates.

pedometer.stop();

Source

src/interfaces/Pedometer.js