Reputation: 40247
how to get direction of one place to another from latitudes and longitudes of both place? as for example if source is Peru or Mexico and destination is Alaska then result should be around clockwise 45 degree north = anticlockwise 45 degree west.
i actually need a function that may return the result taking both lat lon of both source and destination....
I am working in Android. But Here i just seek for the logic/calculation
Advance thanks
Upvotes: 2
Views: 1340
Reputation: 896
This formula will give you the initial heading to depart from the start point to the destination along a great circle:
θ = atan2(sin(Δlong)*cos(lat2), cos(lat1)*sin(lat2) − sin(lat1)*cos(lat2)*cos(Δlong))
Where Δlong
is the overall change in longitude from start to destination and lat1
, lat2
are the latitude of the start/destination.
Note that the heading to the destination will change as you travel along the great circle, thus this heading would need to be continuously adjusted as you move toward the destination. Also note that you will need to map the angles returned by atan2() from +/- pi to 0-360°.
From: http://www.movable-type.co.uk/scripts/latlong.html
Upvotes: 1