LocationCallback
Stay organized with collections
Save and categorize content based on your preferences.
Public Constructor Summary
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Constructors
public LocationCallback ()
Public Methods
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eLocationCallback\u003c/code\u003e receives location updates from the \u003ccode\u003eFusedLocationProviderClient\u003c/code\u003e and provides callbacks for location availability and new location data.\u003c/p\u003e\n"],["\u003cp\u003eIt's suitable for scenarios requiring batched locations or location availability updates, although \u003ccode\u003eLocationListener\u003c/code\u003e might be simpler for basic use cases.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eonLocationAvailability\u003c/code\u003e is called when the availability of location data changes, indicating whether future location updates are likely.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eonLocationResult\u003c/code\u003e delivers a batch of new locations, which might not always represent the current location, so checking timestamps is recommended.\u003c/p\u003e\n"]]],["`LocationCallback` receives location updates from `FusedLocationProviderClient`. It handles batched location data via `onLocationResult(LocationResult)`, receiving multiple locations at once. `onLocationAvailability(LocationAvailability)` notifies about location data availability changes. If location is unavailable, further `onLocationResult` calls are unlikely. When available, more results can be expected. `onLocationResult` may provide one or more locations, clients should check timestamps for recency. A default empty `LocationCallback` constructor is available.\n"],null,["# LocationCallback\n\npublic abstract class **LocationCallback** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nA callback for receiving locations from the [FusedLocationProviderClient](/android/reference/com/google/android/gms/location/FusedLocationProviderClient).\n\nThis differs from [LocationListener](/android/reference/com/google/android/gms/location/LocationListener)\nin that this callback is slightly more work to implement and use, but will receive batches of\nlocation (in the event that a [LocationRequest](/android/reference/com/google/android/gms/location/LocationRequest)\nallows for batched locations) as a single callback to [onLocationResult(LocationResult)](/android/reference/com/google/android/gms/location/LocationCallback#onLocationResult(com.google.android.gms.location.LocationResult)), and will receive callbacks for changes to\n[LocationAvailability](/android/reference/com/google/android/gms/location/LocationAvailability)\nin [onLocationAvailability(LocationAvailability)](/android/reference/com/google/android/gms/location/LocationCallback#onLocationAvailability(com.google.android.gms.location.LocationAvailability)). For most simple location use cases\nclients will often find [LocationListener](/android/reference/com/google/android/gms/location/LocationListener)\neasier to use. \n\n### Public Constructor Summary\n\n|---|--------------------------------------------------------------------------------------------------------------|\n| | [LocationCallback](/android/reference/com/google/android/gms/location/LocationCallback#LocationCallback())() |\n\n### Public Method Summary\n\n|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [onLocationAvailability](/android/reference/com/google/android/gms/location/LocationCallback#onLocationAvailability(com.google.android.gms.location.LocationAvailability))([LocationAvailability](/android/reference/com/google/android/gms/location/LocationAvailability) availability) Invoked when there is a change in the availability of location data. |\n| void | [onLocationResult](/android/reference/com/google/android/gms/location/LocationCallback#onLocationResult(com.google.android.gms.location.LocationResult))([LocationResult](/android/reference/com/google/android/gms/location/LocationResult) result) Invoked when a new set of locations is available. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public **LocationCallback** ()\n\nPublic Methods\n--------------\n\n#### public void **onLocationAvailability** ([LocationAvailability](/android/reference/com/google/android/gms/location/LocationAvailability) availability)\n\nInvoked when there is a change in the availability of location data.\n\nWhen [LocationAvailability.isLocationAvailable()](/android/reference/com/google/android/gms/location/LocationAvailability#isLocationAvailable()) returns `false` it\ngenerally indicates that further invocations of [onLocationResult(LocationResult)](/android/reference/com/google/android/gms/location/LocationCallback#onLocationResult(com.google.android.gms.location.LocationResult)) are unlikely until something changes with\nthe device's settings or environment. When [LocationAvailability.isLocationAvailable()](/android/reference/com/google/android/gms/location/LocationAvailability#isLocationAvailable()) returns `true` it\ngenerally indicates that further invocations of [onLocationResult(LocationResult)](/android/reference/com/google/android/gms/location/LocationCallback#onLocationResult(com.google.android.gms.location.LocationResult)) are likely, and fresh locations can be\nexpected.\n\nClients should treat [LocationAvailability](/android/reference/com/google/android/gms/location/LocationAvailability)\nas a best guess that is not necessarily accurate and should not be relied upon. \n\n#### public void **onLocationResult** ([LocationResult](/android/reference/com/google/android/gms/location/LocationResult) result)\n\nInvoked when a new set of locations is available. The [LocationResult](/android/reference/com/google/android/gms/location/LocationResult)\nmay contain one or more locations, but will never be empty. The locations within the\nlocation result will generally be as fresh as possible given the parameters of the\nassociated [LocationRequest](/android/reference/com/google/android/gms/location/LocationRequest)\nand the state of the device, but this does not imply that they will always represent\nthe current location. Clients should always check the timestamps associated with the\nlocations if necessary for their needs."]]