How do I determine the distance the user has traveled when designing a pedometer application?
I'm designing a pedometer applicat开发者_JAVA技巧ion for the iPhone. Given the number of steps a user has taken, how do I determine the distance in miles they have traveled?
If you are using CLLocation
Class then
Try to implement CLLocationSpeed
which will give you the speed at which device is moving in meters/second.
Ex.
CLLocation *locationObject;
double calculateSpeedMPS=locationObject.speed;
// 1 meter per second = 2.23693629 miles per hour
double calculateSpeedMPH=calculateSpeedMPS*2.23693629;
To calculate the speed, you also need to know the total time the user has spent walking.
If the user has walked M miles for total of T minutes, the average speed is (M * 60) / T
mph. If the user has made a total of S steps for that same time, he's been doing an average of S / (T * 60)
steps per second.
If you know the number of miles, divide it by hours. Voila, miles per hour. Per second, further divide by 3600 and you'll have miles per second. If Google is right, 1 mile = 5280 feet, so by multiplying the last result by feet, you'll have feet per second.
// assuming miles and hours is known
mph = miles / hours;
fps = mph / 3600 * 5280;
The user should have a friend take a picture of them (with their phone) striding over a 12" ruler. Preferably, the photographer has the camera parallel to the ruler. Let them click on both toes and both ends of the ruler and do the math to calculate stride length (est). If you know the number of steps...
精彩评论