FusedLocationProviderApi

public interfaceFusedLocationProviderApi

This interface is deprecated.
Use the GoogleApi-based APIFusedLocationProviderClient instead.

The main entry point for interacting with the fused location provider.

The methods must be used in conjunction with aGoogleApiClient. E.g.


new GoogleApiClient.Builder(context)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build()

Constant Summary

String KEY_LOCATION_CHANGED This constant is deprecated. Use LocationResult.hasResult(Intent)and LocationResult.extractResult(Intent).You may also receiveLocationAvailability in the Intent which you can access using LocationAvailability.hasLocationAvailability(Intent)and LocationAvailability.extractLocationAvailability(Intent).
String KEY_MOCK_LOCATION This constant is deprecated. Prefer to use LocationCompat.isMock()from the compat libraries.

Public Method Summary

abstractPendingResult<Status>
flushLocations(GoogleApiClient client)
Flushes any locations currently being batched and sends them to all registered LocationListeners, LocationCallbacks, andPendingIntents.
abstractLocation
getLastLocation(GoogleApiClient client)
Returns the best most recent location currently available.
abstractLocationAvailability
getLocationAvailability(GoogleApiClient client)
Returns the availability of location data.
abstractPendingResult<Status>
removeLocationUpdates(GoogleApiClient client,PendingIntent callbackIntent)
Removes all location updates for the given pending intent.
abstractPendingResult<Status>
removeLocationUpdates(GoogleApiClient client,LocationListener listener)
Removes all location updates for the given location listener.
abstractPendingResult<Status>
removeLocationUpdates(GoogleApiClient client,LocationCallback callback)
Removes all location updates for the given location result listener.
abstractPendingResult<Status>
requestLocationUpdates(GoogleApiClient client,LocationRequest request,LocationListener listener)
Requests location updates.
abstractPendingResult<Status>
requestLocationUpdates(GoogleApiClient client,LocationRequest request,LocationCallback callback,Looperlooper)
Requests location updates with a callback on the specified Looper thread.
abstractPendingResult<Status>
requestLocationUpdates(GoogleApiClient client,LocationRequest request,LocationListener listener,Looperlooper)
Requests location updates with a callback on the specified Looper thread.
abstractPendingResult<Status>
requestLocationUpdates(GoogleApiClient client,LocationRequest request,PendingIntent callbackIntent)
Requests location updates with a callback on the specified PendingIntent.
abstractPendingResult<Status>
setMockLocation(GoogleApiClient client,Location mockLocation)
Sets the mock location to be used for the location provider.
abstractPendingResult<Status>
setMockMode(GoogleApiClient client, boolean isMockMode)
Sets whether or not the location provider is in mock mode.

Constants

public static finalString KEY_LOCATION_CHANGED

This constant is deprecated.
Use LocationResult.hasResult(Intent)and LocationResult.extractResult(Intent).You may also receiveLocationAvailability in the Intent which you can access using LocationAvailability.hasLocationAvailability(Intent)and LocationAvailability.extractLocationAvailability(Intent).

Key used for a Bundle extra holding aLocation value when a location change is broadcast using a PendingIntent.

Constant Value: "com.google.android.location.LOCATION"

public static finalString KEY_MOCK_LOCATION

This constant is deprecated.
Prefer to use LocationCompat.isMock()from the compat libraries.

Key used for the Bundle extra inLocation object holding a boolean indicating whether the location was set using setMockLocation(GoogleApiClient, Location).If the value is false this extra is not set.

Constant Value: "mockLocation"

Public Methods

public abstractPendingResult<Status> flushLocations(GoogleApiClient client)

Flushes any locations currently being batched and sends them to all registered LocationListeners, LocationCallbacks, andPendingIntents. This call is only useful when batching is specified using LocationRequest.setMaxWaitTime(long),otherwise locations are already delivered immediately when available.

When the returnedPendingResult is complete, then you can assume that any pending batched locations have already been delivered.

public abstractLocation getLastLocation(GoogleApiClient client)

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.

Parameters
client An existing GoogleApiClient. If not connected null will be returned.

public abstractLocationAvailability getLocationAvailability(GoogleApiClient client)

Returns the availability of location data. When LocationAvailability.isLocationAvailable()returns true, then the location returned by getLastLocation(GoogleApiClient)will be reasonably up to date within the hints specified by the activeLocationRequests.

If the client isn't connected to Google Play services and the request times out, null is returned.

Note it's always possible for getLastLocation(GoogleApiClient)to return null even when this method returns true (e.g. location settings were disabled between calls).

Parameters
client An existing GoogleApiClient. If not connected null will be returned.

public abstractPendingResult<Status> removeLocationUpdates(GoogleApiClient client,PendingIntent callbackIntent)

Removes all location updates for the given pending intent.

It is possible for this call to cancel the PendingIntent under some circumstances.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
callbackIntent The PendingIntent that was used in requestLocationUpdates(GoogleApiClient, LocationRequest, PendingIntent) or is equal as defined by PendingIntent.equals(Object).
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.

public abstractPendingResult<Status> removeLocationUpdates(GoogleApiClient client,LocationListener listener)

Removes all location updates for the given location listener.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
listener The listener to remove.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.

public abstractPendingResult<Status> removeLocationUpdates(GoogleApiClient client,LocationCallback callback)

Removes all location updates for the given location result listener.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
callback The callback to remove.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.

public abstractPendingResult<Status> requestLocationUpdates(GoogleApiClient client,LocationRequest request,LocationListener listener)

Requests location updates.

This method is suited for the foreground use cases, more specifically for requesting locations while being connected toGoogleApiClient. For background use cases, thePendingIntent 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 aLooperis recommended for cases where the callback needs to happen on a specific thread. See requestLocationUpdates(GoogleApiClient, LocationRequest, LocationListener, Looper).

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
request The location request for the updates.
listener The listener for the location updates.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.
Throws
IllegalStateException If this method is executed in a thread that has not called Looper.prepare().

public abstractPendingResult<Status> requestLocationUpdates(GoogleApiClient client,LocationRequest request,LocationCallback callback,Looper looper)

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 toGoogleApiClient. For background use cases, thePendingIntent version of the method is recommended, see requestLocationUpdates(GoogleApiClient, LocationRequest, PendingIntent).

Any previous LocationRequests registered on this LocationListener will be replaced.

Callbacks forLocationCallback will be made on the specified thread, which must already be a prepared looper thread.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
request The location request for the updates.
callback The callback 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.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.
Throws
IllegalStateException If looper is null and this method is executed in a thread that has not called Looper.prepare().

public abstractPendingResult<Status> requestLocationUpdates(GoogleApiClient client,LocationRequest request,LocationListener listener,Looper looper)

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 toGoogleApiClient. For background use cases, thePendingIntent 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 aLoopercan be used.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto 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.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.
Throws
IllegalStateException If looper is null and this method is executed in a thread that has not called Looper.prepare().

public abstractPendingResult<Status> requestLocationUpdates(GoogleApiClient client,LocationRequest request,PendingIntent callbackIntent)

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 aPendingIntent for a started service. For foreground use cases, theLocationListener version of the method is recommended, see requestLocationUpdates(GoogleApiClient, LocationRequest, LocationListener).

Any previously registered requests that have the same PendingIntent (as defined by PendingIntent.equals(Object)) will be replaced by this request.

BothLocationResult andLocationAvailability are sent to the given PendingIntent. You can extract data from an Intent using LocationResult.hasResult(Intent), LocationResult.extractResult(Intent), LocationAvailability.hasLocationAvailability(Intent),and LocationAvailability.extractLocationAvailability(Intent).

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
request The location request for the updates.
callbackIntent A pending intent to be sent for each location update.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.

public abstractPendingResult<Status> setMockLocation(GoogleApiClient client,Location mockLocation)

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.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
mockLocation The mock location. Must have a minimum number of fields set to be considered a valild location, as per documentation in theLocation class.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.
Throws
SecurityException if the ACCESS_MOCK_LOCATION permission is not present or the Settings.Secure.ALLOW_MOCK_LOCATIONsystem setting is not enabled.

public abstractPendingResult<Status> setMockMode(GoogleApiClient client, boolean isMockMode)

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 theFusedLocationProviderApi, 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.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
isMockMode If true the location provider will be set to mock mode. If false it will be returned to its normal state.
Returns
  • a PendingResult for the call, checkStatus.isSuccess() to determine if it was successful.
Throws
SecurityException if the ACCESS_MOCK_LOCATION permission is not present or the Settings.Secure.ALLOW_MOCK_LOCATIONsystem setting is not enabled.