Coordinates based on distance and bearing from a known point

NeoTechni

Well-Known Member
Licensed User
Longtime User
We can find the bearing/distance from one location to another, could you add the ability to find the location if we add a bearing/distance to it?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The distanceTo and bearingTo methods are available in the Android SDK. You can use this code to calculate the target location based on the bearing and distance values:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim l1, l3 As Location
   l1.Initialize2(30, 30)
   l3 = CreateLocation(l1, 2000 , 360)
   Log(l3.Latitude & " " & l3.Longitude)
End Sub

Sub CreateLocation (Location1 As Location, Distance As Double, Bearing As Double) As Location
   Dim lat, lon, dlon As Double
   Dim lat1, lon1, tc, d As Double
   tc = -Bearing / 180 * cPI
   lat1 = Location1.Latitude / 180 * cPI
   lon1 = Location1.Longitude / 180 * cPI
   d = Distance  / 1852 * cPI / (180 * 60)
   
   lat =ASin(Sin(lat1)*Cos(d)+Cos(lat1)*Sin(d)*Cos(tc))
    dlon=ATan2(Sin(tc)*Sin(d)*Cos(lat1),Cos(d)-Sin(lat1)*Sin(lat))
   lon = (lon1-dlon +cPI) - 2*cPI * Floor(((lon1-dlon +cPI)) / (2 * cPI)) - cPI
   Dim l As Location
   l.Initialize2(lat * 180 / cPI, lon * 180 / cPI)
   Return l
End Sub
It is based on this page: Aviation Formulary V1.46
 

StillLearning

Member
Licensed User
Longtime User
I tried the code above but get a problem with Location.

I read that it's in the android sdk and I've been using B4A for almost a year, so I assume libraries are in place but apparently not.

Could someone please give me directions to resolve this issue.

Thank You
 
Top