AI-generated Key Takeaways
-
LocationCallback
receives location updates from theFusedLocationProviderClient
and provides callbacks for location availability and new location data. -
It's suitable for scenarios requiring batched locations or location availability updates, although
LocationListener
might be simpler for basic use cases. -
onLocationAvailability
is called when the availability of location data changes, indicating whether future location updates are likely. -
onLocationResult
delivers a batch of new locations, which might not always represent the current location, so checking timestamps is recommended.
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 |
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.