Android Question Text on Googlemaps

Terradrones

Active Member
Licensed User
Hi All

I need a punch in the right direction please.

I have the following codes that converts my grid Coordinates to Lats\Longs and plots the points on Googlemap. The points are circles. How can I display the name of each coordinate point (Circle) next to each Point?

B4X:
[/
Sub PlotPoints(A As Int)
    Dim AveY, AveX As Double
    Dim cp As CameraPosition
    Dim Co As CircleOptions
        
    Co.Initialize
    Try
        Gmap.Clear
    
        If CGlobals.CoordCode=1 Then
            'Site Coords
            Dim rs As ResultSet = CGlobals.sql1.ExecQuery("SELECT Name, East, North, Elevation, Description FROM SCoords")
        else if CGlobals.CoordCode=2 Then
            'Global Coords
            Dim rs As ResultSet = CGlobals.sql1.ExecQuery("SELECT Name, East, North, Elevation, Description FROM GCoords")
        Else
            'Job Coords
            Dim rs As ResultSet = CGlobals.sql1.ExecQuery("SELECT Name, East, North, Elevation, Description FROM Coords")
        End If
        i=0: AveY=0: AveX=0
        
        Do While rs.NextRow
            Dim row(5) As Object
            row(0) = rs.GetString("Name")
            row(1) = NumberFormat2(rs.GetDouble("East"),1,3,3,False)
            row(2) = NumberFormat2(rs.GetDouble("North"),1,3,3,False)
            Geo.get_point_From_local(row(1),row(2))
            Co.StrokeWidth(2)
            
            If Engine.Lat<>0 And Engine.Lon<>0 Then
            'GmapExtra.AddMarker(Engine.Lon,Engine.Lat, row(0))
                'Gmap.AddMarker(Engine.Lon,Engine.Lat, row(0))
                
                Co.Center2(Engine.Lon,Engine.Lat).Radius(5).FillColor(Colors.White).StrokeColor(Colors.DarkGray)
                GmapExtra.AddCircle(Gmap,Co)
                i=i+1
                AveY=AveY+row(1)
                AveX=AveX+row(2)
            End If
        Loop
        rs.Close
        If (AveY<>0 Or AveX<>0) And A=0 Then
            'Zoom in to center of points
            AveY=AveY/i
            AveX=AveX/i
            Geo.get_point_From_local(AveY,AveX)
            cp.Initialize(Engine.Lon,Engine.Lat,10)
            Gmap.MoveCamera(cp)
        End If
    Catch
        Log(LastException)
    End Try
    
End Sub
]
 

Harris

Expert
Licensed User
Longtime User
The other option is to draw the text with canvas and show it with AddMarker3

Regarding Erel's suggestion...

 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
If you have your points stored in a table in a spatialite database , tehn you can use a function like this

B4X:
Public Sub Get_Nearest_point (p1 As Coordinate,TABLENAME As String) As List
  Dim min_dist As Double
  Dim RESULTSet As List
  Dim POINT1 As GPSPoint
  Dim str_poly As StringBuilder
  str_poly.Initialize
 str_poly.Append("ST_DISTANCE(ST_GeomFromText('POINT(").Append(p1.Longitude).Append(" ").Append(p1.Latitude)
 str_poly.Append(")',4326),Geometry)")
  Dim SpatialiteStatement As Spatialite_Stmt
  Dim SQL_STR As String
 SQL_STR="SELECT PK_UID,COMMENT,AsText(Geometry)," & str_poly & " AS DIST FROM " & TABLENAME & " ORDER BY DIST ASC LIMIT 1;"
' Log(SQL_STR)
 SpatialiteStatement=SpatialiteDatabase.Prepare(SQL_STR)
      Do While  SpatialiteStatement.Step
                POINT1.Initialize
                POINT1.PK_UID=SpatialiteStatement.ColumnLong(0)
                POINT1.COMMENT=SpatialiteStatement.ColumnString(1)
                POINT1.Geometry=SpatialiteStatement.ColumnString(2)
                min_dist=111128 * SpatialiteStatement.ColumnDouble(3) 
                'Log(min_dist)
            If min_dist<20 Then
               If Not(RESULTSet.IsInitialized) Then
                    RESULTSet.Initialize
               End If
           RESULTSet.ADD(POINT1)
           End If
     Loop
    SpatialiteStatement.Close
    'Log("res= " & RESULTSet)
    Return RESULTSet
End Sub

you must take care of your field names in the query.
the function can be called from the MapFragment_Click or MapFragment_LongClick event
After geting the result for the info of the desired point you can follow Erel's suggestion
George
 
Upvote 0
Top