Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Pedometer

Improve this doc

Fetch pedestrian-related pedometer data, such as step counts and other information about the distance travelled.

Repo: https://github.com/leecrossley/cordova-plugin-pedometer

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-pedometer
    $ npm install --save @ionic-native/pedometer@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Pedometer } from '@ionic-native/pedometer';

Pedometer.isDistanceAvailable()
  .then((available: boolean) => console.log(available))
  .catch((error: any) => console.log(error));

Pedometer.startPedometerUpdates()
   .subscribe((data: IPedometerData) => {
     console.log(data);
   });

Instance Members

isStepCountingAvailable()

Checks if step counting is available. Only works on iOS.

Returns: Promise<boolean> Returns a promise that resolves when feature is supported (true) or not supported (false)

isDistanceAvailable()

Distance estimation indicates the ability to use step information to supply the approximate distance travelled by the user. This capability is not supported on all devices, even with iOS 8. Only works on iOS.

Returns: Promise<boolean> Returns a promise that resolves when feature is supported (true) or not supported (false)

isFloorCountingAvailable()

Floor counting indicates the ability to count the number of floors the user walks up or down using stairs. This capability is not supported on all devices, even with iOS 8. Only works on iOS.

Returns: Promise<boolean> Returns a promise that resolves when feature is supported (true) or not supported (false)

startPedometerUpdates()

Starts the delivery of recent pedestrian-related data to your Cordova app.

When the app is suspended, the delivery of updates stops temporarily. Upon returning to foreground or background execution, the pedometer object begins updates again.

Returns: Observable<IPedometerData> Returns a Observable that recieves repeatly data from pedometer in background.

stopPedometerUpdates()

Stops the delivery of recent pedestrian data updates to your Cordova app.

Returns: Promise<boolean> Returns a promise that resolves when pedometer watching was stopped

queryData(options)

Retrieves the data between the specified start and end dates. The startDate and endDate options are required and can be constructed in any valid JavaScript way (e.g. new Date(2015, 4, 1, 15, 20, 00) is also valid, as is milliseconds). Only works on iOS.

Param Type Details
options any

start date and en date where you want to get pedometer data

Returns: Promise<IPedometerData> Returns a promise that resolves when pedometer data found

API

Native

General