LocationCompat

public final class LocationCompat
extends Object

java.lang.Object
   ↳ androidx.core.location.LocationCompat


Helper for accessing features in Location.

Summary

Public methods

static long getElapsedRealtimeMillis(Location location)

Return the time of this fix, in milliseconds of elapsed real-time since system boot.

static long getElapsedRealtimeNanos(Location location)

Return the time of this fix, in nanoseconds of elapsed real-time since system boot.

static boolean isMock(Location location)

Returns true if this location is marked as a mock location.

static void setMock(Location location, boolean mock)

Sets whether this location is marked as a mock location.

Inherited methods

Public methods

getElapsedRealtimeMillis

public static long getElapsedRealtimeMillis (Location location)

Return the time of this fix, in milliseconds of elapsed real-time since system boot.

Parameters
location Location

Returns
long

getElapsedRealtimeNanos

public static long getElapsedRealtimeNanos (Location location)

Return the time of this fix, in nanoseconds of elapsed real-time since system boot.

This value can be reliably compared to SystemClock.elapsedRealtimeNanos(), to calculate the age of a fix and to compare location fixes. This is reliable because elapsed real-time is guaranteed monotonic for each system boot and continues to increment even when the system is in deep sleep (unlike getTime().

All locations generated by the LocationManager are guaranteed to have a valid elapsed real-time.

NOTE: On API levels below 17, this method will attempt to provide an elapsed realtime based on the difference between system time and the location time. This should be taken as a best "guess" at what the elapsed realtime might have been, but if the clock used for location derivation is different from the system clock, the results may be inaccurate.

Parameters
location Location

Returns
long

isMock

public static boolean isMock (Location location)

Returns true if this location is marked as a mock location. If this location comes from the Android framework, this indicates that the location was provided by a test location provider, and thus may not be related to the actual location of the device.

NOTE: On API levels below 18, the concept of a mock location does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to read a boolean extra with the key "mockLocation" and use the result to determine whether this should be considered a mock location.

Parameters
location Location

Returns
boolean

setMock

public static void setMock (Location location, 
                boolean mock)

Sets whether this location is marked as a mock location.

NOTE: On API levels below 18, the concept of a mock location does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to set a boolean extra with the key "mockLocation" to mark the location as mock. Be aware that this will overwrite any prior extra value under the same key.

Parameters
location Location

mock boolean