Android Question Invalid marker position on googlemap

Pooya1

Active Member
Licensed User
Hi
I have many location that i show their with Polyline on googlemap and it is correct
I try use bearing for marker direction on googlemap but is is not exact
My code for get bearing marker (marker direction)
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
photo_2018-11-09_10-55-02.png
 
Top