B4J Question Suggest, Auto-complete textfield with Addresses/Locations (Map, Google)

Magma

Expert
Licensed User
Longtime User
Hi there,

If anyone goes to Google Maps and start typing will see suggested address (with no of street too).. Is there anything that i can to have it at my textfields/combobox too... ??

And the best part when doing from Google is when you zoomed at Town, city, village / search is much better...

Using a service like Mapnik (that is free or Google with a key if needed)...

For b4a - i ve found a solution:

For b4j - found too with a little fixes will be ok:
But how on this can put limits (lower lat-lon, higher lat-lon) ?
 
Last edited:

Magma

Expert
Licensed User
Longtime User
Hey i ve found your example for b4a... and just change it a little...

but where i can put limits and how i will change the language of result ? (returns the address in english - i want to return in greek)...

B4X:
Sub search4locations(addr As String)
    Dim Key As String = "MYKEY"
    Dim postString As String
    Dim su As StringUtils
    Dim dir As HttpJob
    dir.Initialize("",Me)
      
    postString="address=" & su.EncodeUrl(addr,"UTF8") & "&Key=" & Key
  

    Log("https://maps.googleapis.com/maps/api/geocode/json?"&postString)
  

    dir.download("https://maps.googleapis.com/maps/api/geocode/json?" & postString)
    Wait For (dir) JobDone(dir As HttpJob)
    If dir.Success Then
   
        Dim jp As JSONParser
        jp.Initialize(dir.GetString)
        Dim m As Map = jp.NextObject
        Dim results As List = m.Get("results")
        For Each colresults As Map In results
        Dim formatted_address As String = colresults.Get("formatted_address")
        Dim types As List = colresults.Get("types")
        For Each coltypes As String In types
        Next
        Dim geometry As Map = colresults.Get("geometry")
        Dim viewport As Map = geometry.Get("viewport")
        Dim southwest As Map = viewport.Get("southwest")
        Dim lng As Double = southwest.Get("lng")
        Dim lat As Double = southwest.Get("lat")
        Dim northeast As Map = viewport.Get("northeast")
        Dim lng As Double = northeast.Get("lng")
        Dim lat As Double = northeast.Get("lat")
        Dim location As Map = geometry.Get("location")
        Dim lng As Double = location.Get("lng")
        Dim lat As Double = location.Get("lat")
        Dim location_type As String = geometry.Get("location_type")
        Dim address_components As List = colresults.Get("address_components")
        For Each coladdress_components As Map In address_components
            Dim types As List = coladdress_components.Get("types")
            For Each coltypes As String In types
            Next
            Dim short_name As String = coladdress_components.Get("short_name")
            Dim long_name As String = coladdress_components.Get("long_name")
        Next
        Dim place_id As String = colresults.Get("place_id")
    Next
    Dim status As String = m.Get("status")
    End If
    dir.Release

        Log(m)


End Sub
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
B4X:
Sub search4locations2(addr As String)
    Dim Key As String = "mykey"
    Dim bounds As String ="40.868825,23.250299|41.438562,24.033075" 'limits
    Dim postString As String
    Dim su As StringUtils
    Dim dir As HttpJob
    dir.Initialize("",Me)

      
    'postString="address=" & addr.Replace(" ","+").trim &"&bounds=" & bounds & "&key=" & Key
  

    'Log("https://maps.googleapis.com/maps/api/geocode/json?"&postString)
  

    dir.download2("https://maps.googleapis.com/maps/api/geocode/json",Array As String("address",addr,"bounds",bounds,"language","el","country","gr","key",Key))
    Wait For (dir) JobDone(dir As HttpJob)
    If dir.Success Then
   
        Dim jp As JSONParser
        jp.Initialize(dir.GetString)
        Dim m As Map = jp.NextObject
        Dim results As List = m.Get("results")
        For Each colresults As Map In results
        Dim formatted_address As String = colresults.Get("formatted_address")
        Dim types As List = colresults.Get("types")
        For Each coltypes As String In types
        Next
        Dim geometry As Map = colresults.Get("geometry")
        Dim viewport As Map = geometry.Get("viewport")
        Dim southwest As Map = viewport.Get("southwest")
        Dim lng As Double = southwest.Get("lng")
        Dim lat As Double = southwest.Get("lat")
        Dim northeast As Map = viewport.Get("northeast")
        Dim lng As Double = northeast.Get("lng")
        Dim lat As Double = northeast.Get("lat")
        Dim location As Map = geometry.Get("location")
        Dim lng As Double = location.Get("lng")
        Dim lat As Double = location.Get("lat")
        Dim location_type As String = geometry.Get("location_type")
        Dim address_components As List = colresults.Get("address_components")
        For Each coladdress_components As Map In address_components
            Dim types As List = coladdress_components.Get("types")
            For Each coltypes As String In types
            Next
            Dim short_name As String = coladdress_components.Get("short_name")
            Dim long_name As String = coladdress_components.Get("long_name")
        Next
        Dim place_id As String = colresults.Get("place_id")
    Next
    Dim status As String = m.Get("status")
    End If
    dir.Release

  log(formatted_address)
   

End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
its and how i will change the language of result ?
see documentation. There is a parameter for the language

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…