Greg
Greg

Reputation: 147

Accuracy of distance between latitude longitude pairs

I need to sort a set of addresses based on the distance from a specifc point. I have latitude and longitude for all these addressses,I am finding the distance with the below Java code.

Double theDistance = (Math.sin(Math.toRadians(latA)) *
                Math.sin(Math.toRadians(latB)) +
                Math.cos(Math.toRadians(latA)) *
                Math.cos(Math.toRadians(latB)) *
                Math.cos(Math.toRadians(longA - longB)));       
            theDistance = (Math.toDegrees(Math.acos(theDistance))) * 69.09;\

But when I compare the results(I mean the sort order (not the actual distance)) with the actual Google map, they don't match. Is it the case always? or Am I not doing it correct?

We found that for Google/Yahoo map web service has some restrictions as a result we can't use in our application.

What is the best way to find the distance between two addresses given that you have the latitude and longitude.

Upvotes: 1

Views: 600

Answers (2)

Marsellus Wallace
Marsellus Wallace

Reputation: 18611

Vincenty's formula will give you the maximum accuracy.

Haversine's one might be "good enough".

Upvotes: 1

Ferruccio
Ferruccio

Reputation: 100728

I think you might be looking for the Great-Circle Distance.

Upvotes: 1

Related Questions