public abstract class LocationProviderAdapter
extends java.lang.Object
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() |
protected boolean |
hasListeners() |
void |
initialize()
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()
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, above.
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()
determineLocationAge(Location)
.protected long determineLocationAge(Location location)
public void acquireLocation(LocationProviderAdapter.LocationAcquisitionListener listener, long maximumAge, float maximumInaccuracy)