# Coordinate and bearing help

## Recommended Posts

I'm trying to determine my bearings by inputting a starting and destination coordinates but my bearings seem to be off by about 6 degrees. Can I get some help, is my math wrong?

```Global \$startLat = "40.730222780"
Global \$startLong = "-73.996576310"
Global \$endLat = "40.729377235"
Global \$endLong = "-73.977298738"

\$PI = 4 * ATan(1)

;===Turn coordinates into degrees.
\$dLat = _Radian ( Number(\$endLat) - Number(\$startLat) )
\$dLong = _Radian ( Number(\$endLong) - Number(\$startLong) )

;Check which quadrant the coordinate is in and find the degrees
If \$dLong > 0 Then
\$Bearing = 90 - (180 / \$PI) * Atan(\$dLat / \$dLong)
EndIf
If \$dLong < 0 Then
\$Bearing = 270 - (180 / \$PI) * Atan(\$dLat / \$dLong)
EndIf

If \$dLong = 0 Then
If \$dLat > 0 Then \$Bearing = 0
If \$dLat < 0 Then \$Bearing = 180
If \$dLat = 0 Then Return
EndIf

\$Bearing = Round(\$bearing)
MsgBox(0,0,\$Bearing)

#cs
_ConsoleWrite("POI: " & \$NAV_POI_ARRAY[\$X][0] & ", " & \$NAV_POI_ARRAY[\$X][1])
_ConsoleWrite("Degrees: " & \$Bearing & ", Direction = " & getCompassDirection(\$Bearing))
_ConsoleWrite("> Range: " & \$Bearing - 15 & " and " & \$Bearing + 15)
_ConsoleWrite("- True Course: " & \$READTRUECOURSE)
#ce```

I just don't know how anyone will be able to verify their results. But if it's clear what I did wrong, please let me know.

Thanks.

Edited by Champak

##### Share on other sites

Try:

```\$dLat = _Radian ( Abs (Number(\$endLat) - Number(\$startLat) ) )
\$dLong = _Radian ( Abs (Number(\$endLong) - Number(\$startLong) ) )```

Br,

UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Nope, that didn't fix it. It turns out the angle of approach and a few extra feet were making it seem like the bearing was off, but the original code seems to be working properly. Thanks anyway.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...