LocationCallback

public abstract class LocationCallback extends Object

A callback for receiving locations from the FusedLocationProviderClient.

This differs from LocationListener in that this callback is slightly more work to implement and use, but will receive batches of location (in the event that a LocationRequest allows for batched locations) as a single callback to onLocationResult(LocationResult), and will receive callbacks for changes to LocationAvailability in onLocationAvailability(LocationAvailability). For most simple location use cases clients will often find LocationListener easier to use.

Public Constructor Summary

Public Method Summary

void
onLocationAvailability(LocationAvailability availability)
Invoked when there is a change in the availability of location data.
void
onLocationResult(LocationResult result)
Invoked when a new set of locations is available.

Inherited Method Summary

Public Constructors

public LocationCallback ()

Public Methods

public void onLocationAvailability (LocationAvailability availability)

Invoked when there is a change in the availability of location data.

When LocationAvailability.isLocationAvailable() returns false it generally indicates that further invocations of onLocationResult(LocationResult) are unlikely until something changes with the device's settings or environment. When LocationAvailability.isLocationAvailable() returns true it generally indicates that further invocations of onLocationResult(LocationResult) are likely, and fresh locations can be expected.

Clients should treat LocationAvailability as a best guess that is not necessarily accurate and should not be relied upon.

public void onLocationResult (LocationResult result)

Invoked when a new set of locations is available. The LocationResult may contain one or more locations, but will never be empty. The locations within the location result will generally be as fresh as possible given the parameters of the associated LocationRequest and the state of the device, but this does not imply that they will always represent the current location. Clients should always check the timestamps associated with the locations if necessary for their needs.