Elad Benda
Elad Benda

Reputation: 36656

why is distanceTo() not enough to calculate distance?

I read some code and saw this method:

private double calculateDistance(Coordinate coordinate1, Coordinate coordinate2) {
    return coordinate1.distance(coordinate2) * (Math.PI * 6371.0)/ 180;
}

Do someone has an idea why is the last part needed for the calculation?

* (Math.PI * 6371.0)/ 180; ?

Upvotes: 0

Views: 56

Answers (1)

rgettman
rgettman

Reputation: 178253

6371.0 looks like the Earth's radius in km. Multiplying by Math.PI / 180 converts degrees to radians.

This is turning a distance in radians to kilometers.

Upvotes: 1

Related Questions