Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

 Subscribe to receive our newsletter. Subscribe Unsubscribe

## Getting direction from one pushpin to another...

This is a discussion on Getting direction from one pushpin to another... within the MapPoint Desktop Discussion forums, part of the Map Forums category; Is there a way to get the direction, N, S, E, W, etc., from one Pushpin to another? Thanks, Jonathan ...

1. Junior Member White Belt
Join Date
Jul 2005
Posts
6

## Getting direction from one pushpin to another...

Is there a way to get the direction, N, S, E, W, etc., from one Pushpin to another?

Thanks,
Jonathan Knapek

2. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

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.

Code:
```u_16 get_bearing&#40;double lat1, double lon1, double lat2, double lon2&#41;
&#123;
double lat  = lat2 - lat1;
double lon  = &#40;lon2 - lon1&#41; * cos&#40;deg2rad&#40;&#40;lat1 + lat2&#41; / 2&#41;&#41;;
double dist = hypot&#40;lat, lon&#41;;
double bear = rad2deg&#40;acos&#40;lat / dist&#41;&#41;;

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

3. Bear down, Chicago Bears!

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•