public final class PositioningManager
extends java.lang.Object
If the user of the application revokes the ACCESS_FINE_LOCATION permission at runtime
while PositioningManager is active, the application will stop receiving location updates
and methods of PositioningManager will stop functioning properly until the
ACCESS_FINE_LOCATION permission is restored.
| Modifier and Type | Class and Description |
|---|---|
static class |
PositioningManager.LocationMethod
Represents values describing the location method.
|
static class |
PositioningManager.LocationStatus
Represents values describing the location status of a particular location method.
|
static interface |
PositioningManager.OnPositionChangedListener
Represents an interface for position update listeners.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(java.lang.ref.WeakReference<PositioningManager.OnPositionChangedListener> listener)
Adds a
PositioningManager.OnPositionChangedListener to the PositioningManager. |
double |
getAverageSpeed()
Gets the average speed of travel, in meters per second.
|
static PositioningManager |
getInstance()
Get access to the PositioningManager Singleton
|
GeoPosition |
getLastKnownPosition()
Returns the last known (cached) position from the best available provider.
|
PositioningManager.LocationMethod |
getLocationMethod()
Gets the method type used to determine positioning.
|
PositioningManager.LocationStatus |
getLocationStatus(PositioningManager.LocationMethod method)
Gets the status for a specified
LocationMethod. |
GeoPosition |
getPosition()
Gets the
GeoPosition for the current PositioningManager.LocationMethod if available. |
boolean |
hasValidPosition()
Determines whether the current position for the current active
PositioningManager.LocationMethod is
valid. |
boolean |
hasValidPosition(PositioningManager.LocationMethod method)
Determines whether the current position for the specified
LocationMethod is valid. |
boolean |
isActive()
Determines whether the
PositioningManager is active and whether position updates are
being received. |
void |
removeListener(PositioningManager.OnPositionChangedListener listener)
Removes a
PositioningManager.OnPositionChangedListener from the PositioningManager. |
boolean |
start(PositioningManager.LocationMethod method)
Starts receiving position updates from the positioning device.
|
void |
stop()
Stops receiving position updates from the positioning device.
|
public static PositioningManager getInstance()
public boolean start(PositioningManager.LocationMethod method)
The PositioningManager will not be started if the application does not have the
ACCESS_FINE_LOCATION permission at the time of this call.
method - A LocationMethod used to provide position updatestrue if position updates have started being received from the positioning
device, false otherwise.public void stop()
public boolean isActive()
PositioningManager is active and whether position updates are
being received.PositioningManager is actively receiving position updates, false
otherwisepublic boolean hasValidPosition()
PositioningManager.LocationMethod is
valid.hasValidPosition(LocationMethod)public boolean hasValidPosition(PositioningManager.LocationMethod method)
LocationMethod is valid.method - A LocationMethod to check for a valid positionhasValidPosition()public double getAverageSpeed()
public GeoPosition getPosition()
GeoPosition for the current PositioningManager.LocationMethod if available.
Availability of a position can be checked by way of the hasValidPosition() method,
if that method returns false, the best available cached position can be obtained using the
getLastKnownPosition() API.
The position returned is determined by the following criteria:
GeoPositiongetLastKnownPosition()public GeoPosition getLastKnownPosition()
hasValidPosition() returns false).
If hasValidPosition() returns true, please use the getPosition() API.getPosition()public PositioningManager.LocationMethod getLocationMethod()
LocationMethodpublic PositioningManager.LocationStatus getLocationStatus(PositioningManager.LocationMethod method)
LocationMethod.method - A LocationMethod used to determine the location statusLocationMethodpublic void addListener(java.lang.ref.WeakReference<PositioningManager.OnPositionChangedListener> listener)
PositioningManager.OnPositionChangedListener to the PositioningManager.listener - A OnPositionChangedListener to addremoveListener(OnPositionChangedListener)public void removeListener(PositioningManager.OnPositionChangedListener listener)
PositioningManager.OnPositionChangedListener from the PositioningManager.listener - A OnPositionChangedListener to removeaddListener(WeakReference)