View Full Version : Getting direction from one pushpin to another...

11-15-2005, 12:03 PM
Is there a way to get the direction, N, S, E, W, etc., from one Pushpin to another?

Jonathan Knapek

11-15-2005, 01:52 PM

This function calculate the bearing between a vehicle's current position and the endpoint it has to go (hence it's name). It does exacly what you ask. The (lat1 + lat2) / 2 is to get the middlepoint of it to correct longitude if we ar not on equator.

u_16 get_bearing(double lat1, double lon1, double lat2, double lon2)
double lat = lat2 - lat1;
double lon = (lon2 - lon1) * cos(deg2rad((lat1 + lat2) / 2));
double dist = hypot(lat, lon);
double bear = rad2deg(acos(lat / dist));

if &#40;lon < 0&#41; // Western direction
bear = 360 - bear;
return bear;

Eric Frost
11-16-2005, 09:36 AM
Bear down, Chicago Bears!