# Thread: Calculating new Lat/Long from current point, distance & bearing

1. ## Calculating new Lat/Long from current point, distance & bearing

I have been hitting myself over the head for a couple hours now. I am trying to calculate the new latitude & longitude (position) when all I have is old latitude & longitude, distance traveled and direction.
The formula I found online is:

'lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))
'lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))
'd/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius

Any ideas where I may be going wrong? I am getting really strange numbers for output. My Longitude appears fine, but Latitude gives me a number of 0.11xxxxx. I am actually trying to make a litte console application in Visual Basic.net (if anyone here does a little programming, so I included the source code as well)

Sub Main()
Dim latA, lonA As Double
Dim d, θ As Integer
Dim R As Integer = 6372.795477598 ' km

Console.Write("enter latitude: ")
Console.Write("enter longitude: ")
Console.Write("distance: (meters) ")
d = Console.ReadLine 'distance in meters
Console.Write("vector/course: ")
θ = Console.Read 'bearing in degrees

d = (d / R) ' convert distance to radians

Dim latB, lonB As Double

latB = Asin(Sin(latA) * Cos(d / R) + Cos(latA) * Sin(d / R) * Cos(θ))
lonB = lonA + Atan2(Sin(θ) * Sin(d / R) * Cos(latA), Cos(d / R) - Sin(latA) * Sin(latB))

Console.WriteLine("destination = " & latB & ", " & lonB)

End Sub

2. Hi Salsa17,

I don't have a copy of vb.net handy, but I'm pretty sure the trig functions require angles in radians, not degrees. So latA, lonA, and theta must all be converted from degrees to radians before their use in trig formulas, and latB and lonB will be in radians too when computed, so you must convert them to degrees before printing, assuming you want your output in degrees.