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

#### Cr8zy1van

##### New member
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

My full console app is simply this:

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

Any ideas where I may be going wrong? I am getting really strange numbers for output.

#### Budius

##### Well-known member
purely the VB part of your code looks fine.
The problem is: there is some deep math + physics necessary there that I found difficult for anyone around here to just know from heart.

My suggestion is to find a physics forum, they'll might be more capable of giving you the answer you need.
And I give you this suggestion based on pure experience, I needed before for a PLC controller to program difference between dates, I resourced to a math forum and had exactly the results I needed.

##### New member
A couple of suggestions - convert the latitude and longitude in to radians as well (and then convert it back again at the end) and the units of d is in metres and R is listed in KM, so try converting d to KM.

Hope this helps

Alastair