public abstract class LocationManager extends Object
The LocationManager is the main entry to retrieveLocation or to bind a LocationListener,
important: in order to use location on iOS you will need to define the build
argument ios.locationUsageDescription
.
This build argument should be used to describe to Apple & the users why you need to use the location
functionality.
Trivial one time usage of location data can look like this sample:
You can also track location in the foreground using API calls like this:
The sample below demonstrates the usage of the background geofencing API:
Modifier and Type | Field and Description |
---|---|
static int |
AVAILABLE |
static int |
OUT_OF_SERVICE |
static int |
TEMPORARILY_UNAVAILABLE |
Constructor and Description |
---|
LocationManager() |
Modifier and Type | Method and Description |
---|---|
void |
addGeoFencing(Class GeofenceListenerClass,
Geofence gf)
Adds a geo fence listener to gets an event once the device is in/out of
the Geofence range.
|
protected void |
bindBackgroundListener()
Bind the Background LocationListener to get events
|
protected abstract void |
bindListener()
Bind the LocationListener to get events
|
protected void |
clearBackgroundListener()
Stop deliver events for the Background LocationListener
|
protected abstract void |
clearListener()
Stop deliver events for the LocationListener
|
protected Class |
getBackgroundLocationListener()
Gets the LocationListener class that handles background location updates.
|
abstract Location |
getCurrentLocation()
Gets the current Location of the device, in most cases this uses the GPS.
|
Location |
getCurrentLocationSync()
Returns the current location synchronously, this is useful if you just want
to know the location NOW and don't care about tracking location.
|
Location |
getCurrentLocationSync(long timeout)
Returns the current location synchronously, this is useful if you just want
to know the location NOW and don't care about tracking location.
|
abstract Location |
getLastKnownLocation()
Gets the last known Location of the device.
|
protected LocationListener |
getListener() |
protected LocationListener |
getLocationListener()
Allows the implementation to notify the location listener of changes to location
|
static LocationManager |
getLocationManager()
Gets the LocationManager instance
|
protected LocationRequest |
getRequest()
Gets the LocationRequest
|
int |
getStatus()
Gets the Manager status: AVAILABLE, OUT_OF_SERVICE or TEMPORARILY_UNAVAILABLE
|
boolean |
isBackgroundLocationSupported()
Returns true if the platform is able to track background location.
|
boolean |
isGeofenceSupported()
Returns true if the platform supports Geofence
|
boolean |
isGPSDetectionSupported()
Returns true if the platform is able to detect if the GPS is on or off.
|
boolean |
isGPSEnabled()
Returns GPS on/off state if isGPSDetectionSupported() returns true
|
void |
removeGeoFencing(String id)
Stop tracking a Geofence
if isGeofenceSupported() returns false this method does nothing
|
void |
setBackgroundLocationListener(Class locationListener)
Use this method to track background location updates when the application
is not running anymore.
|
void |
setLocationListener(LocationListener l)
Sets a LocationListener on the device, use this method if you need to be
updated on the device Locations rather then calling getCurrentLocation.
|
void |
setLocationListener(LocationListener l,
LocationRequest req)
Sets a LocationListener on the device, use this method if you need to be
updated on the device Locations rather then calling getCurrentLocation.
|
protected void |
setStatus(int status)
Allows the implementation to set the status of the location
|
public static final int AVAILABLE
public static final int OUT_OF_SERVICE
public static final int TEMPORARILY_UNAVAILABLE
public static LocationManager getLocationManager()
public int getStatus()
protected void setStatus(int status)
status
- the new statuspublic abstract Location getCurrentLocation() throws IOException
IOException
- if Location cannot be retrieve from the deviceprotected final LocationListener getListener()
public Location getCurrentLocationSync()
public Location getCurrentLocationSync(long timeout)
timeout
- timeout in milliseconds or -1 to never timeoutpublic abstract Location getLastKnownLocation()
public void setLocationListener(LocationListener l)
l
- a LocationListener or null to stop the current listener
from getting updatespublic void setLocationListener(LocationListener l, LocationRequest req)
l
- a LocationListener or null to stop the current listener
from getting updatesreq
- provide the settings in which we are interested to get updates
to the Listener.public void setBackgroundLocationListener(Class locationListener)
locationListener
- a class that implements the LocationListener interface
this class must have an empty constructor since the underlying implementation will
try to create an instance and invoke the locationUpdated methodpublic void addGeoFencing(Class GeofenceListenerClass, Geofence gf)
NOTE: For iOS you must include the ios.background_modes
build hint with a value that includes "location" for geofencing to work.
GeofenceListenerClass
- a Class that implements the GeofenceListener interface
this class must have an empty constructorgf
- a Geofence to trackpublic void removeGeoFencing(String id)
NOTE: For iOS you must include the ios.background_modes
build hint with a value that includes "location" for geofencing to work.
id
- a Geofence id to stop trackingprotected LocationListener getLocationListener()
protected LocationRequest getRequest()
protected Class getBackgroundLocationListener()
NOTE: For iOS you must include the
ios.background_modes
build hint with a value that includes
"location" for background locations to work.
protected abstract void bindListener()
protected abstract void clearListener()
protected void bindBackgroundListener()
protected void clearBackgroundListener()
public boolean isGPSDetectionSupported()
public boolean isBackgroundLocationSupported()
NOTE: For iOS you must include the ios.background_modes
build hint with a value that includes "location" for background locations to work.
public boolean isGeofenceSupported()
NOTE: For iOS you must include the ios.background_modes
build hint with a value that includes "location" for geofencing to work.
public boolean isGPSEnabled()