Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: best method to calculate distance between two locations

I researched a little in this topic, but there are many opinions that don't exactly give a clear image. My problem is this: I'm developing a GPS-based app for Android, in which I want to know distance between my current location specified by Androids LocationManager, and other location in real time. I tried Haversine formula, a Law of Cosines formula, then I discovered, that Android SDK gives me a simple function Location.distanceTo(Location) - I'm not sure what method does this function runs on.

So, the point is, which one will be good for me to use, in situations when real distance between these locations most of the time won't be larger than aprox. 100-200m? Maybe I should check Vincenty's formulae? Is it really that slow? Can someone please explain me what should I choose?

like image 454
Bartek Boro Avatar asked Oct 10 '22 15:10

Bartek Boro


1 Answers

Don't use distanceTo. Use the distanceBetween method as it sounds like you already have the coordinates and that's all you need with this method: Location.distanceBetween() Javadoc

like image 103
SBerg413 Avatar answered Oct 13 '22 10:10

SBerg413