Android Question Geocoder Library - Problem

BernhardS

Member
Licensed User
Longtime User
Hello,

i have a problem with the Geocoder Library. I use the Version 2.01. I want to convert latitude and longtitude to a street name with number and the country. The compiler tells me:

Parsing code. 0.01
Compiling code. Error
Error compiling program.
Error description: Cannot assign void value.
Occurred on line: 28
Results = Geocoder1.GetFromLocation(42.53252, 11.49774, 5, Null)
Word: )

hier is my code:

B4X:
Sub Process_Globals
    Dim Geocoder1 As Geocoder
End Sub

Sub Globals
    Dim Results() As Address
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")   
   
    Geocoder1.Initialize("Geocoder1")   
    Results = Geocoder1.GetFromLocation(42.53252, 11.49774, 5, Null)
    Msgbox("Adress", Results)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

rboeck

Well-Known Member
Licensed User
Longtime User
Hi

you have to delete: results =

and make a subroutine with

sub Geocoder1_GeocodeDone(Results() as address, Tag as object)
....


Because the Geocoding routines are asynchron its a little more complicated to then a function...

Reinhard
 
Upvote 0

BernhardS

Member
Licensed User
Longtime User
The MesseageBox always shows ""No Address matched the Latitude and Longtitude".
What can I do?

my new code is:

B4X:
Sub Process_Globals
    Dim Geocoder1 As Geocoder
End Sub

Sub Globals
    Dim Resultslist As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("GetFromLocation")  
    Geocoder1.Initialize("Geocoder1")
  
End Sub

Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
  
        Resultslist.Clear
      
  
  
    If Results.Length>0 Then
        Dim Address1 As Address
        Dim i As Int
        For i=0 To Results.Length-1
            Address1=Results(i)              
            Resultslist.AddSingleLine(Address1.CountryName)          
        Next
    Else
        Msgbox("GetFromLocation", "No Address matched the Latitude and Longitude")
    End If  
  
End Sub

Sub Button1_Click

Geocoder1.Initialize("Geocoder1")
Geocoder1.GetFromLocation(48.427456055560,11.589683151257074, 5, Null)
End Sub
 
Last edited:
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Hi to bayern,

i have tried your code; now everything is ok. I get Allershausen as Adress.Adresslines. The code is ok.

Reinhard
 
Upvote 0

BernhardS

Member
Licensed User
Longtime User
I have tried the code on my smartphone and on my tablet again, but it doesn´t work.
Is there another library to convert gps coordinates to addresses?
 
Upvote 0

jsanchezc

Member
Licensed User
Longtime User
I had same problem, i reconnect Wifi and Geocoder doesn't work.

While i do more test with Geocoder, to get Latitude / Longitude from Address
i changed code to do call google web page, sending address by httpjob and parse
web result to get latitude and longitude:
<code>
Sub Class_Globals
../..
Dim job2 As HttpJob
../..
End Sub


Sub AskGoogle(AddressSearch As String)
Dim WebURL As String =""

WebURL = "http://maps.google.com/maps?q="
WebURL = WebURL & AddressSearch.Trim.Replace (" ", "%20")
job2.Initialize( "Job_GetLatLng", Me)
Try
job2.PostString(WebURL,"")
Catch
ToastMessageShow("Error: " & job2.ErrorMessage ,True)
End Try
End Sub

Sub
JobDone (job As HttpJob)
Dim ResultGoogle As String=""
Dim StartData As Int =0
Dim DataLatLng As String =""
Dim res() As String

If job.Success = True Then
Select job.JobName
Case "Job_GetLatLng"
ResultGoogle = job.GetString
ResultGoogle=ResultGoogle.ToLowerCase
StartData = ResultGoogle.IndexOf ("{center:{lat:") + 9
If StartData > 2 Then
ResultGoogle=ResultGoogle.SubString(StartData)
DataLatLng = ResultGoogle.indexof("},")
ResultGoogle = ResultGoogle.SubString2 ( 0,DataLatLng)
ResultGoogle=ResultGoogle.Replace ("lat:","")
ResultGoogle=ResultGoogle.Replace ("lng:","")
End If
End Select
End If
Try
job.Release
Catch
Log(LastException.Message)
End Try
' ToastMessageShow(ResultGoogle,True)
CenterLonLat.Lat="41.52368"
CenterLonLat.Lng ="2.03637"

res=Regex.Split (",",ResultGoogle )
If res.Length >0 Then
If res.Length >1 Then
ToastMessageShow("Lat:" & res(0) & ",Lng:" & res(1),true)
End If
End If

End Sub
</code>
 
Last edited:
Upvote 0
Top