public abstract class LocationProviderAdapter
extends java.lang.Object
implements android.os.Parcelable
Modifier and Type | Class and Description |
---|---|
static interface |
LocationProviderAdapter.LocationAcquisitionListener
Callback for when the device's location has been determined.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
mAreLocationUpdatesRunning |
Constructor and Description |
---|
LocationProviderAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
acquireLocation(LocationProviderAdapter.LocationAcquisitionListener listener,
long maximumAge,
float maximumInaccuracy)
Acquire the current location, and will implicitly initiate requests for (future) location updates.
|
void |
addLocationListener(LocationListener listener)
Adds a listener that is called when a location update is received.
|
protected abstract void |
cancelLocationUpdates()
Stops all location updates.
|
void |
deinitialize()
Deinitializes the adapter.
|
protected long |
determineLocationAge(Location location)
A convenience for determining how much time has elapsed since the given update's timestamp.
|
abstract Location |
getLastKnownLocation()
Returns the last location that was received by the adapter's underlying location service.
|
abstract java.lang.String |
getLocationProviderId()
Returns an id that uniquely identifies the concrete implementation of this interface.
|
protected boolean |
hasListeners() |
void |
initialize(android.content.Context context)
Initialize the adapter.
|
protected void |
notifyListenersLocationChanged(Location location)
Called by an implementation when an update has been received from its underlying location
provider.
|
void |
removeLocationListener(LocationListener listener)
Removes the given listener.
|
abstract void |
requestLocationUpdates()
Initiate recurring location updates at a fixed interval.
|
public void initialize(android.content.Context context)
The base implementation of this method takes no action and is intended to be overridden by
subclasses that need to do work that can't be done on demand. For example,
a PlayLocationProviderAdapter (uses PlayServices) connects to a Service, which can't be done
synchronously, preventing it from being done lazily from a method like
getLastKnownLocation()
.
public void deinitialize()
public void addLocationListener(LocationListener listener)
public abstract void requestLocationUpdates()
Location updates are delivered to each LocationListener
added via addLocationListener(LocationListener)
.
The concrete implementation of this method should immediately initiate recurring location updates at an appropriate interval, typically at a minimum interval of approximately once per second.
CAVEAT: If the location update interval is too long, the Navigation Manager might not perform as expected; conversely, if it is much shorter than once per second, this could prove wasteful of battery-life without any real benefits to navigation accuracy or user-experience.
public void removeLocationListener(LocationListener listener)
listener
- The listener to remove.protected abstract void cancelLocationUpdates()
Cancels the recurring location updates delivered to each LocationListener
that were initiated
by requestLocationUpdates()
.
The concrete implementation of this method should immediately cancel all recurring location updates.
protected boolean hasListeners()
protected void notifyListenersLocationChanged(Location location)
public abstract Location getLastKnownLocation()
Because this value can be quite old if the provider is not currently listening for locations,
do not assume that the last known location is the device's current location. Be sure to check
the location's timestamp. See determineLocationAge(Location)
.
protected long determineLocationAge(Location location)
public void acquireLocation(LocationProviderAdapter.LocationAcquisitionListener listener, long maximumAge, float maximumInaccuracy)
public abstract java.lang.String getLocationProviderId()
Note this id can be any valid string, but ideally should be unique to your specific implementation
of the LocationProviderAdapter
interface.