3 Replies Latest reply on Apr 13, 2018 5:24 AM by Bruce Henry

Degree Bearing Calculated from a Pair on Lat Longs

I have the lat long of one location and the lat long of another. My goal is to calculate the bearing of the line that would connect these two points in degrees. I have tried variations of this equation but cannot get it to work. Here is the current equation I am working with below.

 =ATAN2(COS(lat1)*SIN(lat2)-SIN(lat1)*COS(lat2)*COS(lon2-lon1),SIN(lon2-lon1)*COS(lat2))

I have attached a workbook with what I have so far. Does anybody know how to help me?

Thanks a lot.

• 1. Re: Degree Bearing Calculated from a Pair on Lat Longs

You want the 'y' value as the first argument to the ATAN2 function.  This returns radians so you want to convert to degrees.  Then if you want a bearing you will want to return this normalised to 0..360 instead of -180..180.  I've used your workbook's measure names in the below.

Bearing1

DEGREES(ATAN2(SIN([BH Longitude]-[Longitude])*COS([BH Latitude]),COS([Latitude])*SIN([BH Latitude])-SIN([Latitude])*COS([BH Latitude])*COS([BH Longitude]-[Longitude])))

Bearing

IF [Bearing1] < 0 THEN

360 + [Bearing1]

ELSE

[Bearing1]

END

• 2. Re: Degree Bearing Calculated from a Pair on Lat Longs

Hello Walker,

Please check out this link Calculating Distance | Tableau Software to see if it's helpful to you.

Regards.