Myst
Myst

Reputation: 177

calculate accumulated distance using GPS in android

I am a new user and is new to android programming. I am trying to creating a android application that calculate distance a user traveled using a GPS. one of the examples I can think is like a treadmill where it shows the accumulated distance. except the user will be moving around and using a gps to see how long he walked/run.

i can activate a gps, using LocationManager and LocationListener to get a longitude and latitude. but i do not know how to go from there

all my research shows how to calculate distance traveled between 2 points, A to B in a line,shortest distance. but i wanted to have a real-time accumulated distance no matter in which direction the user is going. or how fast. i do not understand how the logic/math behind the calculation so it is hard for me to come up with a solution. the get.DistanceTo and DistanceBetween also calculate distance in a linear line right? i also heard something about a accelerometer to use with a GPS. but based on my research so far(not too in depth) it also shows a single location, but i also do not know how to calculate distance from there. or how does it works with GPS does i have to use longitude and latitude or others? i'm quite weak in programming but this is a task i have to complete. Thanks

Upvotes: 0

Views: 2598

Answers (2)

MoRe
MoRe

Reputation: 1538

I would stick to the GPS data and not worry with the accelerometer. Then you would have to record the position in defined intervals and just add the distance to the last point every time you check. The closer you want to get to the real distance the more frequently you have to check. You could then make the interval dynamic e.g. check less often if you go faster.

Upvotes: 0

cflinspach
cflinspach

Reputation: 320

The Google Distance Matrix API

Can't take credit for the answer, I got it from Another post

Upvotes: 1

Related Questions