Android Question String Lenght in B4A?

rafaelmotaquintana

Active Member
Licensed User
I have this portion on code
B4X:
    Private res As String, wPolygon As String, wComi As String = Chr(34)
    Private Detalle As Cursor
    Private GetAddressJob As HttpJob
    Private wError As String, wPrimero As String
    wPolygon = "{    " & wComi & "name" & wComi & ":" & wComi & ConfigRECORD.VENDEDORCODIGO & "_" & CURRENT_MAPA & wComi & ",    " & wComi & "geo_json" & wComi & ":{    " & wComi & "type" & wComi & ":" & wComi & "Feature" & wComi & ",    " & wComi & "properties" & wComi & ":{        },    " & wComi & "geometry" & wComi & ":{    " & wComi & "type" & wComi & ":" & wComi & "Polygon" & wComi & ",    " & wComi & "coordinates" & wComi & ":[    [    "
    
    f.OpenDatabasemapas
    Detalle = BaseDatosMapas.ExecQuery("SELECT  *  FROM mapdet where id = " & CURRENT_MAPA & " Order by sec")
    If Detalle.RowCount > 0  Then
        For i=0 To Detalle.RowCount-1
            Detalle.Position = i
            If i = 0 Then
                wPrimero = "[" & f.Nulo(Detalle.GetString("LONG")) & "," & f.Nulo(Detalle.GetString("LAT")) & "]"
            End If
            wPolygon = wPolygon & "[" & f.Nulo(Detalle.GetString("LONG")) & "," & f.Nulo(Detalle.GetString("LAT")) & "],"
        Next
        wPolygon = wPolygon &  wPrimero & "    ]    ]    }    }    }"
    End If


The string wPolygon, breaks and won't hold the complete data. Its not much, after some point, the program adds '.....'. This is a sample

{ "name":"23_2", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-70.42743902653456,18.23881539301068],[-70.427609346807,18.239439200051894],[-70.4279875382781,18.239479640757814],[-70.42837444692852,18.239554790391086],[-70.42862690985203,18.239528679081516],[-70.42887233197689,18.23931915160175],[-70.42907517403364,18.23909784190743],[-70.42923543602228,18.23896027948065],[-70.42926158756018,18.23887589506777],[-70.4291033372283,18.23878705256617],[-70.42882639914751,18.238717952811335],[-70.42848777025938,18.238745656402976],[-70.42818769812584,18.238780683926322],[-70.4278963431716,18.238799471413223],[-70.42743902653456,18.23881539301......


I'd like to know if there's a limitation or something. I've read that a string can hold much than that.
 

emexes

Expert
Licensed User
I understand you're still in the get-the-b'stard-working-first phase, but two quick changes that might clear out the undergrowth are:

1/ positions are massively overprecise (as impressive as the subatomic resolution is, your Map/GPS will likely be struggling to match it), and
2/ eliminate repeated code that adds to wPolygon depending on whether is first row or not

so consider:
B4X:
Dim Separator As String = ""    'changed to comma for rows > 1
For i=0 To Detalle.RowCount-1
    Detalle.Position = i
      
    Dim TempLat As String = NumberFormat2( f.Nulo(Detalle.GetString("LAT")), 1, 5, 5, False)    '~1 m resolution
    Dim TempLon As String = NumberFormat2( f.Nulo(Detalle.GetString("LONG")), 1, 5, 5, False)    '~1 m resolution

    wPolygon = wPolygon & Separator & "[" &  TempLon & "," & TempLat & "]"
    Separator = ","
Next
and perhaps even bring the lon/lat formatting into its own function eg:
B4X:
Sub OneMetreResolution(LonLat As Double) As String
    Return NumberFormat2(LonLat, 1, 5, 5, False)    '1 degree = 40000 km / 350 degrees = 111 km
End Sub
Also, I am mildly confused that the closing brackets for wPolygon are inside an If (and the opening brackets are not) but perhaps that is taken care of elsewhere.
 
Last edited:
Upvote 0
Top