B4A Library GeoLocation

TILogistic

Expert
Licensed User
Longtime User
Hi.

Just a heads up, just tried the lib & attached example, nothing works with the latest beta of b4a. Raising a signature error.
This library has methods that were deprecated in API level 33.
see
You can create and use the methods using javaobject from the android.location.Geocoder API

example:
B4X:
Sub Process_Globals
    Private geocoder As JavaObject
End Sub


Dim context As JavaObject
context.InitializeContext
geocoder.InitializeNewInstance("android.location.Geocoder", Array(context))


' Method to get addresses from a location (latitude, longitude)
Sub GetFromLocation(lat As Double, lon As Double, maxResults As Int) As List
    Dim addresses As List
    addresses.Initialize
    Try
        Dim result As Object
        result = geocoder.RunMethod("getFromLocation", Array(lat, lon, maxResults))  'note: deprecated in API level 33.
        
        ' Convert the result to a B4A list of Address objects
        Dim addressList As List
        addressList.Initialize
        
        Dim addressArray As Object = result
        Dim size As Int = addressArray.RunMethod("size", Null)
        
        For i = 0 To size - 1
            Dim address As Object = addressArray.RunMethod("get", Array(i))
            addressList.Add(address)
        Next
        
        Return addressList
    Catch
        Log(LastException.Message)
    End Try
    Return Null
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…