Android Question Geocoder - call sub

Declan

Well-Known Member
Licensed User
Longtime User
I have the following code that receives fields from a MySQL database table:
B4X:
Sub getTransLastServer(fleet As String)
    Dim msgid As String
    Dim msgdeviceid As String
    Dim msglat As String
    Dim msglon As String
    Dim msgvolts As String
    Dim msgid As String
    Dim msgsignal As String
    Dim msgspeed As String = "000"
    Dim msgdatetime As String
    Dim msgfleet As String
    Dim msgfriendname As String
    
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_trans_last", Array(fleet))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        For Each row() As Object In res.Rows
            msgid = row(res.Columns.Get("id"))
            msgdeviceid = row(res.Columns.Get("devicemac"))
            msglat = row(res.Columns.Get("lat"))
            msglon = row(res.Columns.Get("lon"))
            msgvolts = row(res.Columns.Get("volts"))
            msgsignal = row(res.Columns.Get("csq"))
'            msgspeed = row(res.Columns.Get("speed"))
            msgdatetime = row(res.Columns.Get("tstamp"))
            msgfleet = row(res.Columns.Get("fleet"))
            msgfriendname = row(res.Columns.Get("friendname"))
            
            Log("***************************")
            Log("msgid: " & msgid)
            Log("msgdeviceid: " & msgdeviceid)
            Log("msglat: " & msglat)
            Log("msglon: " & msglon)
            Log("msgvolts: " & msgvolts)
            Log("msgsignal: " & msgsignal)
            Log("msgspeed: " & msgspeed)
            Log("msgdatetime: " & msgdatetime)
            Log("msgfleet: " & msgfleet)
            Log("msgfriendname: " & msgfriendname)
            Log("***************************")
            
            Transactions.Put(1, msgid)
            Transactions.Put(2, msgdeviceid)
            Transactions.Put(3, msglat)
            Transactions.Put(4, msglon)
            Transactions.Put(5, msgvolts)
            Transactions.Put(6, msgid)
            Transactions.Put(7, msgsignal)
            Transactions.Put(8, msgspeed)
            Transactions.Put(9, msgdatetime)
            Transactions.Put(10, msgfleet)
            Transactions.Put(11, msgfriendname)
            
            addFN = msgfriendname
            
            ' Get the street Address
             Geocoder1.GetFromLocation(Transactions.Get(3), Transactions.Get(4), 1, "1")
            
            ' Update table "trans"
            insertTrans(msgid, msgdeviceid, msglat, msglon, msgvolts, msgid, msgsignal, msgspeed, msgdatetime, msgfleet, msgfriendname, myAdd1, myAdd2)
        Next
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

I have this declared in "Globals":
B4X:
   Dim Transactions As Map
 Dim myAdd1 As String
    Dim myAdd2 As String

I then attempt to get the Geocoder to obtain the street address information for each record received from MySQL table with:
B4X:
Geocoder1.GetFromLocation(Transactions.Get(3), Transactions.Get(4), 1, "1")

In this Sub and try to add to Map "Transactions":
B4X:
Private Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
        
    myAdd1 = Results(0).SubThoroughfare & " " & Results(0).Thoroughfare
    myAdd2 = Results(0).SubLocality & ", " & (Results(0).Locality) &", " & Results(0).AdminArea
    
    Transactions.Put(12, myAdd1)
    Transactions.Put(13, myAdd2)
    
    Log("myAdd1: " & myAdd1)
    Log("myAdd2: " & myAdd2)

End Sub

The problem I have is that
Private Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
is not called for each record.
It is only called after Sub getTransLastServer(fleet As String) is complete
 

DonManfred

Expert
Licensed User
Longtime User
The problem I have is that
Private Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
is not called for each record.
You are only accessing the FIRST result.
What about the other entries in Results()?
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
You are only accessing the FIRST result.
What about the other entries in Results()?
Sorry, I don't fully understand.
Do I have to change:
B4X:
myAdd1 = Results(0).SubThoroughfare & " " & Results(0).Thoroughfare
for each record received from MySQL?
For instance:
B4X:
myAdd1 = Results(0).SubThoroughfare & " " & Results(0).Thoroughfare
myAdd2 = Results(0).SubLocality & ", " & (Results(0).Locality) &", " & Results(0).AdminArea
myAdd1 = Results(1).SubThoroughfare & " " & Results(1).Thoroughfare
myAdd2 = Results(1).SubLocality & ", " & (Results(1).Locality) &", " & Results(1).AdminArea
etc
etc
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sorry, I don't fully understand.
I strongly suggest to LEARN the language and what the difference between
B4X:
Results() As Address
and
B4X:
Results As Address
is. One is a single result, the other (first one) is a ARRAY. It may contain zero to X entries.

If you just look at entry 0 (first one) you may miss all other entries (if there are more than one result).

You are member since 9 years now. Time to understand what you are doing.

Upload a small project showing the problem. Really hard to help otherwise.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Upload a small project showing the problem. Really hard to help otherwise.
The only problem I have is that I must call:
B4X:
Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
with:
B4X:
Geocoder1.GetFromLocation(Transactions.Get(3), Transactions.Get(4), 1, "1")
for each:
B4X:
For Each row() As Object In res.Rows
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
he only problem I have is that I must call
do not expect me understanding anything from your post.

Upload a small project showing the problem. I don´t see how we could help here with the information you provide.

I´m out here.
 
Upvote 0
Top