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: ")
latA = Console.ReadLine
Console.Write("enter longitude: ")
lonA = Console.ReadLine
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.
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: ")
latA = Console.ReadLine
Console.Write("enter longitude: ")
lonA = Console.ReadLine
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.