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
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.
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 ( )
- 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
- 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
Last edited: