LocationResult

  • LocationResult is a data class representing a geographic location result from the fused location provider.

  • Locations returned are guaranteed to have valid latitude, longitude, and UTC timestamp, and on API level 17+, elapsed real-time since boot.

  • The class provides methods to create a LocationResult, extract it from an Intent, get the latest location, or retrieve all locations.

  • You can check if an Intent contains a LocationResult using thehasResult method.

public final classLocationResult extendsObject
implementsParcelable

A data class representing a geographic location result from the fused location provider.

All locations returned bygetLocations() are guaranteed to have a valid latitude, longitude, and UTC timestamp. On API level 17 or later they are also guaranteed to have elapsed real-time since boot. All other parameters are optional.

Inherited Constant Summary

From interface android.os.Parcelable
intCONTENTS_FILE_DESCRIPTOR
intPARCELABLE_WRITE_RETURN_VALUE

Field Summary

public static finalCreator<LocationResult>CREATOR

Public Method Summary

staticLocationResult
create(List<Location> locations)
Creates aLocationResult for the given locations.
boolean
staticLocationResult
extractResult(Intent intent)
Extracts theLocationResult from an Intent.
Location
getLastLocation()
Returns the most recent location available in this result, or null if no locations are available.
List<Location>
getLocations()
Returns locations computed, ordered from oldest to newest.
static boolean
hasResult(Intent intent)
Returns true if an Intent contains aLocationResult.
int
String
void
writeToParcel(Parcel parcel, int flags)

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
finalClass<?>
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()
From interface android.os.Parcelable
abstract int
describeContents()
abstract void
writeToParcel(Parcel arg0, int arg1)

Fields

public static finalCreator<LocationResult>CREATOR

Public Methods

public staticLocationResultcreate(List<Location> locations)

Creates aLocationResult for the given locations.

public booleanequals(Object o)

public staticLocationResultextractResult(Intent intent)

Extracts theLocationResult from an Intent.

This is a utility function which extracts theLocationResult from the extras of an Intent that was sent from the fused location provider.

Returns

publicLocationgetLastLocation()

Returns the most recent location available in this result, or null if no locations are available.

publicList<Location>getLocations()

Returns locations computed, ordered from oldest to newest.

No duplicate locations will be returned to any given listener (i.e. locations will not overlap in time between subsequent calls to a listener).

public static booleanhasResult(Intent intent)

Returns true if an Intent contains aLocationResult.

This is a utility function that can be called from inside an intent receiver to make sure the received intent is from the fused location provider.

Returns

public inthashCode()

publicStringtoString()

public voidwriteToParcel(Parcel parcel, int flags)

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.