Android Question Get orientation of location

Pooya1

Active Member
Licensed User
Hi guys
I need know what is orientation of special location
Example to top or bottom or left
I want to show user path on google map and have to show machine marker orientation on it
Thanks
 

Pooya1

Active Member
Licensed User
I think relate code can get orientation
B4X:
Sub GetDirectionLocation(StartLocation As LatLng,EndLocation As LatLng) As Float
   
   Dim angle As Float
   angle   =   finalBearing(StartLocation.Latitude, StartLocation.Longitude, EndLocation.Latitude, EndLocation.Longitude)
   Return angle
   
End Sub

Private Sub finalBearing(lat1 As Double,long1 As Double,lat2 As Double,long2 As Double) As Double
   Return (bearing(lat2, long2, lat1, long1) + 180.0) Mod 360
End Sub

Private Sub bearing(lat1 As Double,long1 As Double,lat2 As Double,long2 As Double) As Double
   
   Dim degToRad,phi1,phi2,lam1,lam2 As Double
   degToRad = cPI / 180.0
   phi1 = lat1 * degToRad
   phi2 = lat2 * degToRad
   lam1 = long1 * degToRad
   lam2 = long2 * degToRad
   Return ATan2(Sin(lam2-lam1)*Cos(phi2),Cos(phi1)*Sin(phi2) - Sin(phi1)*Cos(phi2)*Cos(lam2-lam1)) * 180/cPI
       
End Sub
 
Last edited:
Upvote 0

Pooya1

Active Member
Licensed User
I think relate code can get orientation
B4X:
Sub GetDirectionLocation(StartLocation As LatLng,EndLocation As LatLng) As Float
  
   Dim angle As Float
   angle   =   finalBearing(StartLocation.Latitude, StartLocation.Longitude, EndLocation.Latitude, EndLocation.Longitude)
   Return angle
  
End Sub

Private Sub finalBearing(lat1 As Double,long1 As Double,lat2 As Double,long2 As Double) As Double
   Return (bearing(lat2, long2, lat1, long1) + 180.0) Mod 360
End Sub

Private Sub bearing(lat1 As Double,long1 As Double,lat2 As Double,long2 As Double) As Double
  
   Dim degToRad,phi1,phi2,lam1,lam2 As Double
   degToRad = cPI / 180.0
   phi1 = lat1 * degToRad
   phi2 = lat2 * degToRad
   lam1 = long1 * degToRad
   lam2 = long2 * degToRad
   Return ATan2(Sin(lam2-lam1)*Cos(phi2),Cos(phi1)*Sin(phi2) - Sin(phi1)*Cos(phi2)*Cos(lam2-lam1)) * 180/cPI
      
End Sub
Please evaluate my code
 
Upvote 0
Top