Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Abubakar Abdulrahman
Abubakar Abdulrahman
3,284 Points

How can I Calculate the distance of steps counter in android

I want to implement a 6 min step count. I was able to implement the step count. But i have no idea how to get the distance. Please kindly help

2 Answers

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey Abubakar!

I'm not sure how to do that with location services. Though you could use a standard step size (or even ask the user how large their steps are), and then multiply that by the number of steps to get a distance measurement.

Hope that helps!

Abubakar Abdulrahman
Abubakar Abdulrahman
3,284 Points

Thank you Ben Deitch for your honest answer. But is there a standard of measuring step size using a person's height.

Ben Deitch
Ben Deitch
Treehouse Teacher

Maybe? I'm not aware of one though.

Ashraf Rahman
Ashraf Rahman
6,111 Points

You can use location services and calculate the distance the user has travelled from the starting location, after the 6 minuet period, all you need is to get the starting co-ordinate and the final co-ordinate (Latlng) and then using: SphericalUtil.computeDistanceBetween(latlng1, latlng2); it will provide the distance. You may need to do some research before hand and familiarise yourself with implementing the service, use this: https://developer.android.com/training/building-location.html

Abubakar Abdulrahman
Abubakar Abdulrahman
3,284 Points

@Ashraf Rahman Thank you for the answer. I understand that you can use location services to measure a person's walking distance in 6 minutes but what if the walk is to and fro for 6 minutes. i.e i assume the person might walk from point A and still come back to point A. if you are to calculate the distance from point A to point A that zero using location service. Because usually the 6 minutes walk is done in a particular corridor where the person walks for 6 minutes going to and fro.