Looking for a way to measure distance for workout app


#1

Hello
I am working on a workout app and I am looking for a way to allow users to set a distance (in km) for their activity (run/walk/…) and give a feedback during the activity.
What is the best way to achieve that?
Thanks!


#2

Your question is rather vague, but I would start by looking at the Pedometer plugin.


#3

Why vague?
Think of the following usage:
James wants to go out and run 5 km. He should be able to set distance (5 km) press start and off he goes.
James would like to know when he passes half of the way (after 2.5 km some notification should be sent - probably some audio effect).

This is the second feature of my app.
The first was set time interval for the workout. For example, James can set a walk interval of 10 minutes or a run interval of 3 minutes. I wrote a basic timer for this feature but for the distance feature I need some help :slight_smile:

About the plugin you suggest. How do I install it? I don’t see its documentation on ionic-native doc page.

Thank you for your help.


#4

Looks like it’s there to me.


#5

Oh.
I searched in the wrong tab :blush:
Thank you, I will try it.


#6

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.

I’m working with Android :frowning:

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

07-07 01:14:09.603 D/SystemWebChromeClient(22501): file:///android_asset/www/cordova.js: Line 312 : Error in Error callbackId: Pedometer1206703277 : [object Object]
07-07 01:14:09.603 I/chromium(22501): [INFO:CONSOLE(312)] "Error in Error callbackId: Pedometer1206703277 : [object Object]", source: file:///android_asset/www/cordova.js (312)
07-07 01:14:09.603 D/SystemWebChromeClient(22501): file:///android_asset/www/build/main.js: Line 56034 : false
07-07 01:14:09.603 I/chromium(22501): [INFO:CONSOLE(56034)] "false", source: file:///android_asset/www/build/main.js (56034)

Is there something similar for Android?


#7

Plugin docs say live pedometer data works on Android; can you make something from that?


#8

What am I missing?

try {
  console.log("Starting Pedometer");
  this.pedometer.startPedometerUpdates()
  .subscribe((data: IPedometerData) => {
    console.log(data);
  });
} catch (error) {
  console.error("Something went wrong with Pedometer: ", error);
}
07-07 01:29:27.949 D/SystemWebChromeClient(24493): file:///android_asset/www/build/main.js: Line 56034 : Starting Pedometer
07-07 01:29:27.949 I/chromium(24493): [INFO:CONSOLE(56034)] "Starting Pedometer", source: file:///android_asset/www/build/main.js (56034)
07-07 01:29:28.069 D/SystemWebChromeClient(24493): file:///android_asset/www/cordova.js: Line 312 : Error in Error callbackId: Pedometer431046343 : [object Object]
07-07 01:29:28.069 I/chromium(24493): [INFO:CONSOLE(312)] "Error in Error callbackId: Pedometer431046343 : [object Object]", source: file:///android_asset/www/cordova.js (312)
07-07 01:29:28.089 D/SystemWebChromeClient(24493): file:///android_asset/www/build/main.js: Line 1362 : ERROR
07-07 01:29:28.089 I/chromium(24493): [INFO:CONSOLE(1362)] "ERROR", source: file:///android_asset/www/build/main.js (1362)

What does it mean error in error callback id?


#9

I don’t know; I haven’t actually used this plugin. You may also want to take a look at stepcounter instead.


#10

OK I will check it out.
Tell me please, don’t you think some gps plugin would be better than a step-counter based plugin?


#11

I’m not sure if it’s what you’re after but you could try the geolocation plugin. Just take their start location and calculate the distance travelled between their current location.