Android Question Thousands of markers ...

javiers

Active Member
Licensed User
Longtime User
Hi, I have about 13,000 records in a table. What is the best way to create them as markers without slowing down the application?

Related to this, would it be better to create only markers in the visible part of the map and when you have a certain zoom?

Is this posible?

Thanks in advance!
 

DonManfred

Expert
Licensed User
Longtime User
I would not show any marker which is not at a minimum zoomlevel. 14+
I would not show them too if outside the screenarea.
Is this posible?
Sure. But showing this amount of Markers will slow down.
 
Upvote 0

javiers

Active Member
Licensed User
Longtime User
I would not show any marker which is not at a minimum zoomlevel. 14+
I would not show them too if outside the screenarea.

Sure. But showing this amount of Markers will slow down.


Thank you for your answers!.
I will try to create only the markers when the zoom is at least +14, and only those within the visible area of the map.

I understand that GetProjection (Gmap) .GetVisibleRegion.LatLngBounds can help me ... I would have to query the table to select the markers that are within the visible area, and then create them.


Let's see if I can do it ...
 
Upvote 0

kgf

Member
Licensed User
Im sure there is a much better way to do this, but haven't investigated further. Was going to look at grouping points based on tile bounds at each zoom.

This queries a sqlite view that has lat and lon columns., and groups waypoints by rounding the decimal places based on the zoom.

B4X:
Sub DrawWaypointsClustered(gmap As GoogleMap, swLat As Double, swLong As Double, neLat As Double, neLong As Double, mapzoom As Int)
    
'    1° = 111 km  (Or 60 nautical miles)
'    0.1° = 11.1 km
'    0.01° = 1.11 km (2 decimals, km accuracy)
'    0.001° =111 m
'    0.0001° = 11.1 m
'    0.00001° = 1.11 m
'    0.000001° = 0.11 m (7 decimals, cm accuracy)

'    Dim lStart As Long = DateTime.Now
    
    If mapzoom < 10 Then Return ' dont draw at larger scales
    
    Dim MarkerCluster As Marker 'ignore
    ListClusterMarker.Initialize

    Dim ranges As Map = CreateMap(10: 0, 11: 0, 12: 1, 13: 1, 14: 1, 15: 1, 16: 2, 17: 3, 18: 3)
    Dim zoomRound As Int = ranges.Get(mapzoom)

    Dim strsql As String
    strsql = $"Select count(id) As n, avg(lon) As lon, avg(lat) As lat "$ & _
    "FROM vw_waypoint " & _
    "WHERE " & _
    $"(Case WHEN ${swLat} < ${neLat} Then lat BETWEEN ${swLat} And ${neLat} Else lat BETWEEN ${neLat} And ${swLat} End) "$ & _
    "AND " & _
    $"(Case WHEN ${swLong} < ${neLong} Then lon BETWEEN ${swLong} And ${neLong} Else lon BETWEEN ${neLong} And ${swLong} End) "$ & _
    $"GROUP BY Round(lat,${zoomRound}) , Round(lon,${zoomRound})"$
    Dim rs As ResultSet = Starter.sql.ExecQuery(strsql)
'    Log("draw " & rs.RowCount & " pins")

    Do While rs.NextRow = True
        MarkerCluster = gmap.AddMarker3(rs.GetDouble("lat"),rs.GetDouble("lon"), "", CreateClusterBitmap(rs.GetString("n")))
        ListClusterMarker.Add(MarkerCluster)
    Loop
    rs.Close
'    Dim lEnd As Long = DateTime.Now - lStart
'    Log("addWaypointsClustered took " & lEnd & " m seconds") 'ms to seconds
End Sub

Sub CreateClusterBitmap(text As String) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 200dip, 200dip)
    Dim c As B4XCanvas
    c.Initialize(p)
    c.DrawCircle(c.TargetRect.CenterX, c.TargetRect.Bottom - 50, 50 ,xui.Color_ARGB(200,255,255,255), True, 1)
    c.DrawText(text, c.TargetRect.CenterX, c.TargetRect.Bottom - 40, xui.CreateDefaultBoldFont(20), xui.Color_Black, "CENTER")
    c.Invalidate
    Return c.CreateBitmap
End Sub
 
Upvote 0
Top