B4A Library GeoLocation

This is Library which is based on the code from this Github project.

GeoLocation
...|https://www.b4x.com
Author: DonManfred
Version: 1.1
  • GeoLocator
    • Events:
      • Location (success As Boolean, Lattitude As Double, Longitude As Double)
    • Functions:
      • geoAddress
      • GetLocation
      • Initialize (EventName As String)
    • Properties:
      • Address As String [read only]
      • City As String [read only]
      • Country As String [read only]
      • KnownName As String [read only]
      • Lattitude As Double [read only]
      • Longitude As Double [read only]
      • PostalCode As String [read only]
      • State As String [read only]

If get the Location from the System. It result in using th GPS Provider, Network Provider or PASSIVE_PROVIDER. In the resultevent you get info from which Provider the Location is from.
 

Attachments

  • GeoLocationV1.01.zip
    3 KB · Views: 1,161
  • GeoLocationV1.11.zip
    3.4 KB · Views: 1,562
  • GeoLocEx.zip
    9.3 KB · Views: 1,246
Last edited:

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
 
Top