B4A Library Geocoder library

Marco Nissen

Active Member
Licensed User
Longtime User
I'm getting proper latitude and longitude (confirmed with google maps api), but getFromLocation always returns 0 results (google maps api returns a bunch). Anyone else experience this?

I have the same issue. any help for Marshmallow?
 

MarcoRome

Expert
Licensed User
Longtime User
I have the same issue. any help for Marshmallow?
Try this:


With this line you have this result in json:

With okhttp is done.
 

brunnlechner

Member
Licensed User
Longtime User
Hello,
is there a change in the Geocoder API since 20.06.2017?
On some devices, only NULL addresses are returned since 20.06.2017

Thank you
Franz
 

DonManfred

Expert
Licensed User
Longtime User
On some devices, only NULL addresses are returned
Just a thought: Does the device have the GoogleApis installed?

The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

Honestly i just do not know this lib. In the projects where i needed to have GeoCoding i used the http-api like in the Post #102 from @MarcoRome
 

qnw4ts7pge

Member
Licensed User
Longtime User
I get the following error when trying to access the "AddressLines" list of an Address object:
java.lang.ClassCastException: uk.co.martinpearman.b4a.location.AddressWrapper cannot be cast to android.location.Address
B4X:
'* Note - FoundAddresses is process global
'       Dim FoundAddresses as list

Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
   
   FoundAddresses.Initialize2(Results)

  DumpAddresses(FoundAddresses)
End Sub


Sub DumpAddresses(Addresses As List)
  
   If Addresses.Size>0 Then
     Log("=== GEOCODER ===")
     Log("  Total: "&Addresses.Size)
    
     Dim i As Int, j As Int, sOut As String
    
     For i=0 To Addresses.Size-1
       Dim a As Address
      
       Log("Address("&i&")")
      
       a=Addresses.Get(i)
       Log(a)
       Log(a.AddressLines.Get(0))     '<---- Error here
       Log("---")      
     Next
   Else
     Log("=== GEOCODER ===")
     Log("No Addresses Found")
   End If
End Sub

Any help would be greatly appreciated.
 

qnw4ts7pge

Member
Licensed User
Longtime User
Does it work if you keep it as an array instead of a list?

Interesting.... Your reply got me thinking.

I was assuming that the list.initialize2 method was basically doing the following, but when I code it explicitly, it works.

Changed this:

B4X:
  FoundAddresses.Initialize2(Results)

To this:

B4X:
  If FoundAddresses.IsInitialized Then
     FoundAddresses.Clear
   Else
     FoundAddresses.Initialize
   End If
   
   Dim i As Int
   For i=0 To Results.Length-1
     Dim a As Address
     a=Results(i)
     FoundAddresses.Add(a)
   Next

...and it works perfectly...

Thanks for the quick response, and problem solved.
 

marcick

Well-Known Member
Licensed User
Longtime User
On more of 100 devices where my app is installed, only one seems to suddenly have problems in reverse geocode.
It is a Samsung SM-G920F with Android 7.0. It was working fine for a long time, but suddenly it is not able to show any address.

This is the Geocode_Done code:

B4X:
Dim Address1 As Address
    Dim Adr As String
    If Results.Length>0 Then
        Address1=Results(0)
        Log(Address1)
        If Address1.AddressLines.Size>0 Then
            Adr=Address1.AddressLines.Get(0)
            If Address1.AddressLines.Size>1 Then Adr=Adr & " " & Address1.AddressLines.Get(1)
        Else
            Adr="Unknown address"
        End If
    Else
        Adr="Unknown address"
    End If

Giving a couple of coordinates, this is the normal result (Address1) that I see on the other 99 devices

B4X:
(Address)Address[addressLines=[0:"Via San Giuseppe Benedetto Cottolengo, 13",1:"20037 Paderno Dugnano MI",2:"Italia"],feature=13,admin=null,sub-admin=Città Metropolitana di Milano,locality=Paderno Dugnano,thoroughfare=Via San Giuseppe Benedetto Cottolengo,postalCode=20037,countryCode=IT,countryName=Italia,hasLatitude=true,latitude=45.5720745,hasLongitude=true,longitude=9.1461078,phone=null,url=null,extras=null]

And the above code extracts correctly the address

But on this Samsung, the same couple of coordinates give this result that looks a bit different

B4X:
(Address)Address[addressLines=[0:"Via S. Giuseppe Benedetto Cottolengo, 13, 20037 Paderno Dugnano MI, Italia"],feature=13,admin=Lombardia,sub-admin=Città Metropolitana di Milano,locality=Paderno Dugnano,thoroughfare=Via San Giuseppe Benedetto Cottolengo,postalCode=20037,countryCode=IT,countryName=Italia,hasLatitude=true,latitude=45.5720745,hasLongitude=true,longitude=9.1461078,phone=null,url=null,extras=null]

And the above code fails to extract the address because Address1.AddressLines.Size is 0

Any idea ?
 

marcick

Well-Known Member
Licensed User
Longtime User
I'm trying this workaround:

B4X:
    Dim Address1 As Address
    Dim Adr As String
    If Results.Length>0 Then
        Address1=Results(0)
        Log(Address1)
        If Address1.AddressLines.Size>0 Then
            Adr=Address1.AddressLines.Get(0)
            If Address1.AddressLines.Size>1 Then Adr=Adr & " " & Address1.AddressLines.Get(1)
        Else
            Adr=""
            If Address1.Thoroughfare <> Null Then Adr=Address1.Thoroughfare
            If Address1.SubThoroughfare <> Null Then Adr= Adr & " " & Address1.SubThoroughfare
            If Address1.PostalCode <> Null Then Adr= Adr & " " & Address1.PostalCode
            If Address1.Locality <> Null Then Adr= Adr & " " & Address1.Locality
        End If
    Else
        Adr="Indirizzo sconosciuto"
    End If

but the Address1.Locality contains just "20037 Paderno Dugnano" and should be "20037 Paderno Dugnano MI"
Looks like the text is clipped in the library ?
"MI" is the SubAdminArea as we usually write address in Italy. MI = Milano, TO=Torino, VE=Venezia etc.
If I check Address1.SubAdminArea I obtain "Città Metropolitana di Milano" that looks bad to show
 

Croïd

Active Member
Licensed User
Longtime User

@marcick

I think the problem does not come from the library.

Geocoder not works on sony xperia and works fine on nexus

relationship with google key api !
 
Last edited:

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello to all
I also have problems with address: I have completed standard sample and entered my co-ordinates and can not extract address. See log

reading the post, I did not understand if I should integrate or modify the project to get address from coordinates?!

Latitude = 45.7202
longitude 9.71442
Address1.AddressLines.Size=0
Address1.AddressLines.Size=0
Address1.AddressLines.Size=0
Address1.AddressLines.Size=0
Address1.AddressLines.Size=0


thanks in advice
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Follow my workaround above when addressline.size is 0

visto che siamo della stessa zona, ti rispondo in Italiano. Ho visto e utilizzato il tuo codice, che funziona (grazie). Anche io riscontro il problema della provincia, che penso sia dovuto alle API e non alla libreria. Credo che per risolverlo, si dovrebbe fare una tabella di conversione delle province Italiane.
ciao
 

marcick

Well-Known Member
Licensed User
Longtime User
Yes, probably, but I'll not spend time without precise data to work on.
I'm actually not showing the Address1.SubAdminArea part that looks bad. Post code and city is enough ...
 

SMOOTSARA

Active Member
Licensed User
Longtime User


Hello ?
Isn't this library capable of displaying GMT time ?
If the answer is no, it could be a good option for next updating the library ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…