Samadhan Medge
Samadhan Medge

Reputation: 2049

How to Get latitude & longitude when get turn in Android

I work on application of distance calculator in which I want to calculate total distance traveled. I got some tutorial in which location get periodically. I know how to get location periodically but I want take location(i.e latitude & longitude) when user get turn while traveling.

So I want to know how to user got turn with device so that location should get acquire.For simplicity see the following image in which I want get location of point A,B,C,D,E,F,G,H,I.
enter image description here

Any Further suggestion for distance calculation will appreciate.
Thank You.

Upvotes: 0

Views: 398

Answers (2)

Ridcully
Ridcully

Reputation: 23665

For calculating the distance, it's not necessary to specifically detect turns in the user's way. With LocationManager you can get locations e.g. every seconds. Just sum up the distances between those locations and you're done.

It makes no difference to the distance if you've only position E and F or if you've got 3 extra locations under way.

It may happen that you miss the exact corner, but the LocationManager can provide locations pretty fast, so that's no big problem and the GPS positioning isn't that exact anyway.

Calculating the distance between two Locations

To calculate the distance between two Location objects, use Location.distanceTo() which will give you the distance in meters.

Upvotes: 1

P_M
P_M

Reputation: 328

You can retrieve new location coordinates in a pretty fast rate (for example every second). So use the getBearing()-method every second and then I think you will be able to get every turn if you do a constant comparison with the previous values!

You could also try to calculate a mean bearing-value for the last couple measurements so that you do not exceed your threshold so quickly and identify many corners that you do not want to identify... (these false positives depend on the quality of the GPS and also for example on the environment, because GPS is easily influenced by buildings etc.)

Upvotes: 2

Related Questions