```
Sub DownLoadTiles(BB As TMapBoxLatLng, iMinZoom As Int, iMaxZoom As Int, bEmptyTiles As Boolean, bShowProgress As Boolean) As ResumableSub 'ignore
Dim x As Int
Dim y As Int
Dim z As Int
Dim n As Int
Dim p As Int
Dim t As Int
Dim dMinLat As Double = BB.fRightBottom.fLat
Dim dMaxLat As Double = BB.fLeftTop.fLat
Dim dMinLng As Double = BB.fLeftTop.fLng
Dim dMaxLng As Double = BB.fRightBottom.fLng
Dim iMinX As Int
Dim iMaxX As Int
Dim iMinY As Int
Dim iMaxY As Int
Dim iTilesTotal As Int
Dim iProgressInterval As Int
Dim iTilesRemoved As Int 'ignore
Dim arrLong(2) As Long
General.StartSW(2)
iTilesTotal = MapUtilities.GetTotalTiles(BB, iMinZoom, iMaxZoom)
If bShowProgress Then
If iTilesTotal < 160 Then
iProgressInterval = 1
Else
iProgressInterval = iTilesTotal / 100
End If
End If
If bEmptyTiles Then
iTilesRemoved = emptyDB
End If
If B4XProgressBar1.IsInitialized = False Then
mParent.LoadLayout("ProgressBar")
End If
If bShowProgress Then
B4XProgressBar1.Show(mParent, iTilesTotal, False, 1, "Tiles to download, ", "/", " done")
End If
fDB.BeginTransaction
For z = iMinZoom To iMaxZoom
iMinX = MapUtilities.LngToTileX(dMinLng, z)
iMaxX = MapUtilities.LngToTileX(dMaxLng, z)
iMinY = MapUtilities.LatToTileY(dMaxLat, z)
iMaxY = MapUtilities.LatToTileY(dMinLat, z)
For x = iMinX To iMaxX
For y = iMinY To iMaxY
Dim rs As ResumableSub = getTileFromInternet(z, x, y)
Wait For (rs) Complete (b4xbmp As B4XBitmap)
If b4xbmp.IsInitialized = False Then
fDB.TransactionSuccessful
fDB.EndTransaction
If bShowProgress Then
B4XProgressBar1.Reset
End If
Return arrLong
End If
If setTileToDB(z, x, y, b4xbmp) = False Then
fDB.TransactionSuccessful
fDB.EndTransaction
If bShowProgress Then
B4XProgressBar1.Reset
End If
Return arrLong
End If
n = n + 1
p = p + 1
t = t + 1
If n = 10000 Then
fDB.TransactionSuccessful
fDB.EndTransaction
n = 0
fDB.BeginTransaction
End If
If bShowProgress Then
If p = iProgressInterval Or t = 1 Then
B4XProgressBar1.Progress = t
p = 0
Sleep(0)
End If
End If
Next
Next
Next
fDB.TransactionSuccessful
fDB.EndTransaction
If bShowProgress Then
B4XProgressBar1.Reset
End If
arrLong(0) = t
arrLong(1) = General.StopSW(2)
Return arrLong
End Sub
```