How to calculate short & long distance via Haversine?

Posted by Jeroen on Stack Overflow See other posts from Stack Overflow or by Jeroen
Published on 2010-03-26T13:35:26Z Indexed on 2010/03/26 13:43 UTC
Read the original article Hit count: 671

Filed under:
|

Hi,

I am looking for a way to calculate the distance between 2 points on the globe. We've been told to use Haversine, which works fine to calculate the shortest distance between the 2 points.

Now, I'd like to calculate the "long distance" between to points. So suppose you have 2 cities, A in the west and B in the east. I want to know the distance from B to A if I would travel eastwards around the globe and then reach A coming from the west.

I've tried changing a couple of things in the haversine function, but doesn't seem to work.

Anyone know how I can simply do this using small adjustments to the haversine function?

This is what I'm using now:

lat1, lat2, lng1, lng2 are in radians

part1 = sin(lat2) * sin(lat1); part2 = cos(lat2) * cos(lat1) * cos(lng1 - lng2);

distance = EARTH_RADIUS * acos(part1 + part2);

Tnx Jeroen

© Stack Overflow or respective owner

Related posts about haversine

Related posts about distance