com.google.android.gms.location.FusedLocationProviderApi |
The main entry point for interacting with the fused location provider.
The methods must be used in conjunction with a GoogleApiClient
. E.g.
new GoogleApiClient.Builder(context)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build()
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | KEY_LOCATION_CHANGED | Key used for a Bundle extra holding a Location value when a location change is broadcast using a PendingIntent. | |||||||||
String | KEY_MOCK_LOCATION |
Key used for the Bundle extra in Location object holding a boolean indicating whether
the location was set using setMockLocation(GoogleApiClient, Location) .
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the best most recent location currently available.
| |||||||||||
Removes all location updates for the given location listener.
| |||||||||||
Removes all location updates for the given pending intent.
| |||||||||||
Requests location updates with a callback on the specified Looper thread.
| |||||||||||
Requests location updates.
| |||||||||||
Requests location updates with a callback on the specified PendingIntent.
| |||||||||||
Sets the mock location to be used for the location provider.
| |||||||||||
Sets whether or not the location provider is in mock mode.
|
Key used for a Bundle extra holding a Location value when a location change is broadcast using a PendingIntent.
Key used for the Bundle extra in Location object holding a boolean indicating whether
the location was set using setMockLocation(GoogleApiClient, Location)
. If the value is false this
extra is not set.
Returns the best most recent location currently available.
If a location is not available, which should happen very rarely, null will be returned. The best accuracy available while respecting the location permissions will be returned.
This method provides a simplified way to get location. It is particularly well suited for applications that do not require an accurate location and that do not want to maintain extra logic for location updates.
client | An existing GoogleApiClient. If not connected null will be returned. |
---|
Removes all location updates for the given location listener.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
listener | The listener to remove. |
isSuccess()
to determine if it was
successful.
Removes all location updates for the given pending intent.
It is possible for this call to cancel the PendingIntent under some circumstances.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
callbackIntent | The callback intent to remove. |
isSuccess()
to determine if it was
successful.
Requests location updates with a callback on the specified Looper thread.
This method is suited for the foreground use cases,more specifically
for requesting locations while being connected to GoogleApiClient
. For
background use cases, the PendingIntent
version of the method is recommended, see
requestLocationUpdates(GoogleApiClient, LocationRequest, PendingIntent)
.
Any previous LocationRequests registered on this LocationListener will be replaced.
Callbacks for LocationListener will be made on the specified thread, which must already be a
prepared looper thread. For cases where the callback can happen on the calling thread, the
variant of this method without a Looper
can be used. See requestLocationUpdates(GoogleApiClient, LocationRequest, LocationListener, Looper)
.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
request | The location request for the updates. |
listener | The listener for the location updates. |
looper | The Looper object whose message queue will be used to implement the callback mechanism, or null to make callbacks on the calling thread. |
isSuccess()
to determine if it was
successful.
Requests location updates.
This method is suited for the foreground use cases, more specifically
for requesting locations while being connected to GoogleApiClient
. For
background use cases, the PendingIntent
version of the method is recommended, see
requestLocationUpdates(GoogleApiClient, LocationRequest, PendingIntent)
.
Any previous LocationRequests registered on this LocationListener will be replaced.
Callbacks for LocationListener will be made on the calling thread, which must already be a
prepared looper thread, such as the main thread of the calling Activity. The variant of this
method with a Looper
is recommended for cases where the callback needs to happen on
a specific thread.mResult =
See
requestLocationUpdates(GoogleApiClient, LocationRequest, LocationListener, Looper)
.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
request | The location request for the updates. |
listener | The listener for the location updates. |
isSuccess()
to determine if it was
successful.
Requests location updates with a callback on the specified PendingIntent.
This method is suited for the background use cases, more specifically
for receiving location updates, even when the app has been killed by the system. In order to
do so, use a PendingIntent
for a started service. For foreground use cases, the
LocationListener
version of the method is recommended, see
requestLocationUpdates(GoogleApiClient, LocationRequest, LocationListener)
.
Any previous LocationRequests registered on this PendingIntent will be replaced.
Location updates are sent with a key of KEY_LOCATION_CHANGED
and a Location
value on the intent.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
request | The location request for the updates. |
callbackIntent | A pending intent to be sent for each location update. |
isSuccess()
to determine if it was
successful.
Sets the mock location to be used for the location provider. This location will be used in place of any actual locations from the underlying providers (network or gps).
setMockMode(GoogleApiClient, boolean)
must be called and set to true prior to calling this method.
Care should be taken in specifying the timestamps as many applications require them to be monotonically increasing.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
mockLocation | The mock location. Must have a minimum number of fields set to be
considered a valild location, as per documentation in the
Location class. |
isSuccess()
to determine if it was
successful.
SecurityException | if the ACCESS_MOCK_LOCATION permission is not present or the
Settings.Secure.ALLOW_MOCK_LOCATION system setting is
not enabled. |
---|
Sets whether or not the location provider is in mock mode.
The underlying providers (network and gps) will be stopped (except by direct
LocationManager
access), and only locations specified in
setMockLocation(GoogleApiClient, Location)
will be reported. This will effect all location clients
connected using the LocationClient, including geofencer clients (i.e.
geofences can be triggered based on mock locations).
The client must remain connected in order for mock mode to remain active. If the client dies the system will return to its normal state.
Calls are not nested, and mock mode will be set directly regardless of previous calls.
client | An existing GoogleApiClient. It must be connected at the time of this call,
which is normally achieved by calling connect() and
waiting for onConnected(Bundle)
to be called. |
---|---|
isMockMode | If true the location provider will be set to mock mode. If false it will be returned to its normal state. |
isSuccess()
to determine if it was
successful.
SecurityException | if the ACCESS_MOCK_LOCATION permission is not present or the
Settings.Secure.ALLOW_MOCK_LOCATION system setting is
not enabled. |
---|