LocationCompat

public final class LocationCompat
extends Object

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


Helper for accessing features in Location.

Summary

Constants

String EXTRA_BEARING_ACCURACY

Constant used as a key to store bearing accuracy in Location.getExtras() for Android SDK levels below Oreo (26).

String EXTRA_IS_MOCK

Constant used as a key to store mock location status in Location.getExtras() for Android SDK levels below JBMR2 (18).

String EXTRA_SPEED_ACCURACY

Constant used as a key to store speed accuracy in Location.getExtras() for Android SDK levels below Oreo (26).

String EXTRA_VERTICAL_ACCURACY

Constant used as a key to store vertical accuracy in Location.getExtras() for Android SDK levels below Oreo (26).

Public methods

static float getBearingAccuracyDegrees(Location location)

Get the estimated bearing accuracy of this location in degrees.

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 float getSpeedAccuracyMetersPerSecond(Location location)

Get the estimated speed accuracy of this location in meters per second.

static float getVerticalAccuracyMeters(Location location)

Get the estimated vertical accuracy of this location in meters.

static boolean hasBearingAccuracy(Location location)

Returns true if this location has a bearing accuracy.

static boolean hasSpeedAccuracy(Location location)

Returns true if this location has a speed accuracy.

static boolean hasVerticalAccuracy(Location location)

Returns true if this location has a vertical accuracy.

static boolean isMock(Location location)

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

static void setBearingAccuracyDegrees(Location location, float bearingAccuracyD)

Set the estimated bearing accuracy of this location in degrees.

static void setMock(Location location, boolean mock)

Sets whether this location is marked as a mock location.

static void setSpeedAccuracyMetersPerSecond(Location location, float speedAccuracyMps)

Set the estimated speed accuracy of this location in meters per second.

static void setVerticalAccuracyMeters(Location location, float verticalAccuracyM)

Set the estimated vertical accuracy of this location in meters.

Inherited methods

Constants

EXTRA_BEARING_ACCURACY

public static final String EXTRA_BEARING_ACCURACY

Constant used as a key to store bearing accuracy in Location.getExtras() for Android SDK levels below Oreo (26).

Constant Value: "bearingAccuracy"

EXTRA_IS_MOCK

public static final String EXTRA_IS_MOCK

Constant used as a key to store mock location status in Location.getExtras() for Android SDK levels below JBMR2 (18).

Constant Value: "mockLocation"

EXTRA_SPEED_ACCURACY

public static final String EXTRA_SPEED_ACCURACY

Constant used as a key to store speed accuracy in Location.getExtras() for Android SDK levels below Oreo (26).

Constant Value: "speedAccuracy"

EXTRA_VERTICAL_ACCURACY

public static final String EXTRA_VERTICAL_ACCURACY

Constant used as a key to store vertical accuracy in Location.getExtras() for Android SDK levels below Oreo (26).

Constant Value: "verticalAccuracy"

Public methods

getBearingAccuracyDegrees

public static float getBearingAccuracyDegrees (Location location)

Get the estimated bearing accuracy of this location in degrees.

NOTE: On API levels below 26, the concept of bearing accuracy does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to read a float extra with the key EXTRA_BEARING_ACCURACY and return the result.

Parameters
location Location

Returns
float

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