LocationCallback Stay organized with collections Save and categorize content based on your preferences.
Page Summary
LocationCallback is a callback for receiving locations from the FusedLocationProviderClient.
Unlike LocationListener, LocationCallback can receive batches of locations and provides callbacks for changes in LocationAvailability.
LocationCallback includes methods to handle new location results (onLocationResult) and changes in location availability (onLocationAvailability).
While slightly more complex to implement than LocationListener, LocationCallback is suitable for handling batched location updates and availability changes.
A callback for receiving locations from theFusedLocationProviderClient.
This differs fromLocationListener in that this callback is slightly more work to implement and use, but will receive batches of location (in the event that aLocationRequest allows for batched locations) as a single callback to onLocationResult(LocationResult), and will receive callbacks for changes toLocationAvailability in onLocationAvailability(LocationAvailability). For most simple location use cases clients will often findLocationListener 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
publicLocationCallback()
Public Methods
public voidonLocationAvailability(LocationAvailability availability)
Invoked when there is a change in the availability of location data.
When LocationAvailability.isLocationAvailable() returnsfalse it generally indicates that further invocations of onLocationResult(LocationResult) are unlikely until something changes with the device's settings or environment. When LocationAvailability.isLocationAvailable() returnstrue it generally indicates that further invocations of onLocationResult(LocationResult) are likely, and fresh locations can be expected.
Clients should treatLocationAvailability as a best guess that is not necessarily accurate and should not be relied upon.
public voidonLocationResult(LocationResult result)
Invoked when a new set of locations is available. TheLocationResult 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 associatedLocationRequest 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.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.