Android Question Gps Location/Bearing Line Drawing

daniedb

Active Member
Licensed User
Hi All

Is it possible to draw a Line in a Specific bearing direction, from Current lat/lon coordinates.
Eg: My coordinates = Lat -26.xxxxx, Lon =26.xxxx, bearing/heading eg 200
Now I want to draw a Line (maybe a few pixels) from that coordinates to that direction/bearing?

Hope you understand the question

Thanks
Danie
 

wes58

Active Member
Licensed User
What I do, is to draw a cone (polygon) showing the current bearing. I use it with the StreetView to show on the map position of the camera in the StreetViewPanorama. See on attached picture what it looks like

B4X:
Sub Globals
    Dim GMapsEx As GoogleMapsExtras
    Dim gmap As GoogleMap
    Dim Poly As Polygon
    Dim flagPolygon as Boolean
End Sub

Sub drawPolygon(curLocation As Location)
'lon    0.001093597 = approx. 100m
'lat    0.000901404 = approx. 100m
    Dim PolyOptions1 As PolygonOptions
    Dim Point1, Point2, Point3, Point4 As LatLng
    Dim PointsList As List
    Dim bear1, bear2 As Float
    Dim lat1, lat2, lon1, lon2 As Float
    Dim coneDeg As Int = 10
    Dim scale As Float
    Dim z As Int

    If flagPolygon Then        'remove polygon if it exists
        Poly.Remove
        flagPolygon = False
    End If
    z = NumberFormat(gmap.CameraPosition.Zoom, 1, 0)        'current map zoom
    If z > 10 Then    '13 Then
        scale = (20 - z)/2
        If scale < 1 Then
            scale = 1
        End If
        scale = scale * 0.000901404           'polygon length depends on the map zoom

        bear1 = curLocation.Bearing + coneDeg
        If bear1 > 360 Then
            bear1 = bear1 - 360
        End If
        bear2 = curLocation.Bearing - coneDeg
        If bear2 < 0 Then
            bear2 = 360 + bear2
        End If
        lat1 = scale  * CosD(bear1)           
        lon1 = scale * SinD(bear1)
        lat2 = scale * CosD(bear2)
        lon2 = scale * SinD(bear2)
        lat1 = lat1 + curLocation.Latitude
        lon1 = lon1 + curLocation.Longitude
        lat2 = lat2 + curLocation.Latitude
        lon2 = lon2 + curLocation.Longitude
        flagPolygon = True
   
        PointsList.Initialize
        Point1.Initialize(curLocation.Latitude, curLocation.Longitude)
        PointsList.Add(Point1)
        Point2.Initialize(lat1, lon1)
        PointsList.Add(Point2)
        Point3.Initialize(lat2, lon2)
        PointsList.Add(Point3)
        Point4.Initialize(curLocation.Latitude, curLocation.Longitude)
        PointsList.Add(Point4)   '   closes the path

        PolyOptions1.Initialize
        PolyOptions1.FillColor = Colors.ARGB(128, 242, 195, 247)
        PolyOptions1.Points.AddAll(PointsList)
        PolyOptions1.StrokeColor = Colors.Black
        PolyOptions1.StrokeWidth=2
        Poly = GMapsEx.AddPolygon(gmap, PolyOptions1)
    End If
End Sub
Maybe, there are better solutions but this works for me.
 

Attachments

Last edited:

Beja

Expert
Licensed User
"SVpoly" ??

Hi wes58
What's this undeclared object/variable?
Thanks
 

wes58

Active Member
Licensed User
"SVpoly" ??

Hi wes58
What's this undeclared object/variable?
Thanks
Hi,
It was my mistake because I modified this code (simplified) to show it here and didn't check everything. It should be replaced SVpoly.lat changed to curLocation.Latitude and SVpoly.lon changed to curLocation.Longitude. I updated the code in first post as well.
 

daniedb

Active Member
Licensed User
Hi Wes58

Thanks for Sharing, this might just be what I'm looking for.
Thanks, appreciate
Danie
 
Top