B4A Library Expanded Location Manager Library

Attached is an expanded version of XverhelstX excellent LocationManager library.
It adds new methods and extra functionality to the existing methods. There are many other methods as detailed on Android Dev which can be easily added if required.
The two significant new methods are "findLastLocation" & "addProximityAlert"
findLastLocation is handy when there is no network or gps (bear in mind the position may be way off) it can also return a location from 'passive' provider, this position is updated any time an app requests a position.
ProximityAlert generates an event anytime you cross the boundary as defined by a position and a radius, there are two different events; Enter & Exit.
RequestLocation (Network & GPS) should only be started once each, onResume they do not need to be called again as the Listener remains until the app is killed or the Stop method is called.
esLocation2
Author: Edward Smith
Version: 1
  • ESLocation2
    Events:
    • Locationchanged ( )
    • Providerdisabled ( )
    • Providerenabled ( )
    • Proximityenter ( )
    • Proximityexit ( )
    • Statuschanged ( )
    Methods:
    • EndProximityAlert
      Removes the ProximityAlert pending intent
    • Initialize (EventName As String)
      Common initialisations
      Example:<code>
      Dim MyLocation As ESLocation2
      MyLocation.Initialize("Location")</code>
      Can raise the following Events
      Locationchanged_Location
      Providerdisabled_Location
      Providerenabled_Location
      Statuschanged_Location
      Proximityenter_Location
      Proximityexit_Location
    • addProximityAlert (Radius As Int, Lat As Double, Long As Double, Life As Long)
      Add Proximity Alert
      This method uses both Network and GPS to trigger the Alert, if there is no GPS
      fix then the Network fix will be used and will not be as accurate. This is a
      function of Android and cannot be changed.
      Radius: in meters
      Lat: positive values for north
      Long: negative values for west
      Life: this is the life of the pending Intent in milliseconds, use -1 for no expiration
    • findLastLocation (providerType As String) As List
      Returns the Last Known Location in a 'List' containing:
      provider type
      Time of fix
      Latitude
      Longitude
      Accuracy
      Pass null to get a 'List' of all providers details
      providerType: This can be 'network', 'passive', 'gps' or null
    • requestGPSLocation (mintime As Long, mindistance As Float)
      Starts a GPS Listener for position updates
      See the following Android Dev site <link>requestLocationUpdates|LocationManager | Android Developers, long, float, android.location.LocationListener)</link> for details
      mintime: minimum time interval between location updates, in milliseconds pass 0 for continuous updates
      minDistance: minimum distance between location updates, in meters pass 0 for continuous updates
    • requestNetworkLocation (mintime As Long, mindistance As Float)
      Starts a Network Listener for position updates
      See the following Android Dev site <link>requestLocationUpdates|LocationManager | Android Developers, long, float, android.location.LocationListener)</link> for details
      mintime: minimum time interval between location updates, in milliseconds pass 0 for continuous updates
      minDistance: minimum distance between location updates, in meters pass 0 for continuous updates
    • stopGPSListening
      Stops GPS Listener
    • stopNetworkListening
      Stops Network Listener
    Permissions:
    • android.permission.ACCESS_COARSE_LOCATION
    • android.permission.ACCESS_FINE_LOCATION

v1.1 added, no change to the methods but full annotation added to the @Events.

v1.2 sorted 'findLastLocation(String)' method, this now returns the request list based on the sent parameter e.g. 'network', 'gps', 'network' or null for all.
 

Attachments

  • esLocation2 V1.2.zip
    6.6 KB · Views: 1,880
  • ProximityAlert Demo.zip
    10.9 KB · Views: 1,579
Last edited:

Croïd

Active Member
Licensed User
Longtime User
B4X:
If ..... = DialogResponse.POSITIVE Then

GPS = p.GetSettings("location_providers_allowed")

If GPS.IndexOf("gps")> -1 Then

Msgbox("GPS","OK !")

Else

Msgbox("Activate GPS ! ","Carefulness")

StartActivity(GPS.locationSettingsIntent)
 

Cebuvi

Active Member
Licensed User
Longtime User
B4X:
If ..... = DialogResponse.POSITIVE Then

GPS = p.GetSettings("location_providers_allowed")

If GPS.IndexOf("gps")> -1 Then

Msgbox("GPS","OK !")

Else

Msgbox("Activate GPS ! ","Carefulness")

StartActivity(GPS.locationSettingsIntent)

Thank you very much
 

peacemaker

Expert
Licensed User
Longtime User
Actually, in simplest way, most of app that needs LAST KNOWN coordinates - should have a class or lib, that has commands to:
* check and activate network location (WiFi and cell network), if avalable and allowed in the system settings; else return that not available, or not allowed
* check and activate GPS location, if avalable and allowed in the system settings; else return that not available, or not allowed
* command to get Last_known_location, by the date_time, among both above, and not important which

Such code module would be very ... interesting.
 

Croïd

Active Member
Licensed User
Longtime User
Does that work for you? (version 4.4 may be not work !)


reply : OK works well android V4.4 & V5
 
Last edited:

coslad

Well-Known Member
Licensed User
Longtime User
Doesn't works on Note 3 kitkat, without gps doesn't gets coordinate
 

achtrade

Active Member
Licensed User
Longtime User
HI,

How can i clear an old location that was found . my app seems to record the last location. how would i make the app get the new location instead. (based on network network).

regards,
Tom

I'm getting this same error. How can we fix this ?

My apps is getting the first location but after I call lm.findLastLocation("null") every 5 seconds, the result is the same. I don't need the GPS/WIFI location, please help

B4X:
Sub Activity_Create(FirstTime As Boolean)
    lm.Initialize("Location")
    myList.Initialize
end 

Sub timer2_Tick
    myList = lm.findLastLocation("null")
    passiveLat = NumberFormat(myList.Get(7), 0, 9)
    passiveLong  = NumberFormat(myList.Get(8), 0, 9)
End Sub
 

hookshy

Well-Known Member
Licensed User
Longtime User
My apps is getting the first location but after I call lm.findLastLocation("null") every 5 seconds, the result is the same. I don't need the GPS/WIFI location, please help

try to read myList size ...in this way you will find out that ..element number 7 and 8 does not exist
I am not the creator but I took some protections by code and try to read what is availlable
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
I have a customer with a parking lot and want that people from the car ask for things to delivery to the car. So the guy park in a spot and using an app request stuff that will be taken to him. If I can triangulate with the Wifi antennas of that customer I could know in wich direction the car is parked.

Is it possible?
 
Top