LocationCompat
class LocationCompat
Helper for accessing features in android.location.Location.
Summary
Constants |
|
|---|---|
const String! |
EXTRA_BEARING_ACCURACY = "bearingAccuracy"Constant used as a key to store bearing accuracy in |
const String! |
EXTRA_IS_MOCK = "mockLocation"Constant used as a key to store mock location status in |
const String! |
EXTRA_MSL_ALTITUDE = "androidx.core.location.extra.MSL_ALTITUDE"Constant used as a key to store Mean Sea Level altitude in |
const String! |
EXTRA_MSL_ALTITUDE_ACCURACY = "androidx.core.location.extra.MSL_ALTITUDE_ACCURACY"Constant used as a key to store Mean Sea Level altitude in |
const String! |
EXTRA_SPEED_ACCURACY = "speedAccuracy"Constant used as a key to store speed accuracy in |
const String! |
EXTRA_VERTICAL_ACCURACY = "verticalAccuracy"Constant used as a key to store vertical accuracy in |
Public functions |
|
|---|---|
java-static Float |
getBearingAccuracyDegrees(location: Location)Get the estimated bearing accuracy of this location in degrees. |
java-static Long |
getElapsedRealtimeMillis(location: Location)Return the time of this fix, in milliseconds of elapsed real-time since system boot. |
java-static Long |
@ReplaceWith(expression = "location.getElapsedRealtimeNanos()")This function is deprecated. Call |
java-static @FloatRange(from = 0.0) Float |
getMslAltitudeAccuracyMeters(location: Location)Returns the estimated Mean Sea Level altitude accuracy in meters of the location at the 68th percentile confidence level. |
java-static Double |
getMslAltitudeMeters(location: Location)Returns the Mean Sea Level altitude of the location in meters. |
java-static Float |
getSpeedAccuracyMetersPerSecond(location: Location)Get the estimated speed accuracy of this location in meters per second. |
java-static Float |
getVerticalAccuracyMeters(location: Location)Get the estimated vertical accuracy of this location in meters. |
java-static Boolean |
hasBearingAccuracy(location: Location)Returns true if this location has a bearing accuracy. |
java-static Boolean |
hasMslAltitude(location: Location)Returns true if the location has a Mean Sea Level altitude, false otherwise. |
java-static Boolean |
hasMslAltitudeAccuracy(location: Location)Returns true if the location has a Mean Sea Level altitude accuracy, false otherwise. |
java-static Boolean |
hasSpeedAccuracy(location: Location)Returns true if this location has a speed accuracy. |
java-static Boolean |
hasVerticalAccuracy(location: Location)Returns true if this location has a vertical accuracy. |
java-static Boolean |
Returns true if this location is marked as a mock location. |
java-static Unit |
removeBearingAccuracy(location: Location)Removes the bearing accuracy from the location. |
java-static Unit |
removeMslAltitude(location: Location)Removes the Mean Sea Level altitude from the location. |
java-static Unit |
removeMslAltitudeAccuracy(location: Location)Removes the Mean Sea Level altitude accuracy from the location. |
java-static Unit |
removeSpeedAccuracy(location: Location)Removes the speed accuracy from the location. |
java-static Unit |
removeVerticalAccuracy(location: Location)Removes the vertical accuracy from the location. |
java-static Unit |
setBearingAccuracyDegrees(location: Location, bearingAccuracyD: Float)Set the estimated bearing accuracy of this location in degrees. |
java-static Unit |
Sets whether this location is marked as a mock location. |
java-static Unit |
setMslAltitudeAccuracyMeters(Sets the Mean Sea Level altitude accuracy of the location in meters. |
java-static Unit |
setMslAltitudeMeters(location: Location, mslAltitudeMeters: Double)Sets the Mean Sea Level altitude of the location in meters. |
java-static Unit |
setSpeedAccuracyMetersPerSecond(Set the estimated speed accuracy of this location in meters per second. |
java-static Unit |
setVerticalAccuracyMeters(location: Location, verticalAccuracyM: Float)Set the estimated vertical accuracy of this location in meters. |
Constants
EXTRA_BEARING_ACCURACY
const val EXTRA_BEARING_ACCURACY = "bearingAccuracy": String!
Constant used as a key to store bearing accuracy in getExtras for Android SDK levels below Oreo (26).
EXTRA_IS_MOCK
const val EXTRA_IS_MOCK = "mockLocation": String!
Constant used as a key to store mock location status in getExtras for Android SDK levels below JBMR2 (18).
EXTRA_MSL_ALTITUDE
const val EXTRA_MSL_ALTITUDE = "androidx.core.location.extra.MSL_ALTITUDE": String!
Constant used as a key to store Mean Sea Level altitude in getExtras.
EXTRA_MSL_ALTITUDE_ACCURACY
const val EXTRA_MSL_ALTITUDE_ACCURACY = "androidx.core.location.extra.MSL_ALTITUDE_ACCURACY": String!
Constant used as a key to store Mean Sea Level altitude in getExtras.
EXTRA_SPEED_ACCURACY
const val EXTRA_SPEED_ACCURACY = "speedAccuracy": String!
Constant used as a key to store speed accuracy in getExtras for Android SDK levels below Oreo (26).
EXTRA_VERTICAL_ACCURACY
const val EXTRA_VERTICAL_ACCURACY = "verticalAccuracy": String!
Constant used as a key to store vertical accuracy in getExtras for Android SDK levels below Oreo (26).
Public functions
getBearingAccuracyDegrees
java-static fun getBearingAccuracyDegrees(location: Location): Float
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.
| See also | |
|---|---|
getBearingAccuracyDegrees |
getElapsedRealtimeMillis
java-static fun getElapsedRealtimeMillis(location: Location): Long
Return the time of this fix, in milliseconds of elapsed real-time since system boot.
| See also | |
|---|---|
getElapsedRealtimeNanos |
@ReplaceWith(expression = "location.getElapsedRealtimeNanos()")
java-static fungetElapsedRealtimeNanos(location: Location): Long
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.
getMslAltitudeAccuracyMeters
java-static fun getMslAltitudeAccuracyMeters(location: Location): @FloatRange(from = 0.0) Float
Returns the estimated Mean Sea Level altitude accuracy in meters of the location at the 68th percentile confidence level. This means that there is 68% chance that the true Mean Sea Level altitude of the location falls within getMslAltitudeMeters +/- this uncertainty.
This is only valid if hasMslAltitudeAccuracy is true.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude 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_MSL_ALTITUDE_ACCURACY and return the result.
| See also | |
|---|---|
getMslAltitudeAccuracyMeters |
getMslAltitudeMeters
java-static fun getMslAltitudeMeters(location: Location): Double
Returns the Mean Sea Level altitude of the location in meters.
This is only valid if hasMslAltitude is true.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to read a double extra with the key EXTRA_MSL_ALTITUDE and return the result.
| See also | |
|---|---|
getMslAltitudeMeters |
getSpeedAccuracyMetersPerSecond
java-static fun getSpeedAccuracyMetersPerSecond(location: Location): Float
Get the estimated speed accuracy of this location in meters per second.
NOTE: On API levels below 26, the concept of speed 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_SPEED_ACCURACY and return the result.
| See also | |
|---|---|
getSpeedAccuracyMetersPerSecond |
getVerticalAccuracyMeters
java-static fun getVerticalAccuracyMeters(location: Location): Float
Get the estimated vertical accuracy of this location in meters.
NOTE: On API levels below 26, the concept of vertical 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_VERTICAL_ACCURACY and return the result.
| See also | |
|---|---|
getVerticalAccuracyMeters |
hasBearingAccuracy
java-static fun hasBearingAccuracy(location: Location): Boolean
Returns true if this location has a bearing accuracy.
| See also | |
|---|---|
hasBearingAccuracy |
hasMslAltitude
java-static fun hasMslAltitude(location: Location): Boolean
Returns true if the location has a Mean Sea Level altitude, false otherwise.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude does not exist. In order to allow for backwards compatibility and testing however, this method will return true if an extra value is with the key EXTRA_MSL_ALTITUDE.
| See also | |
|---|---|
hasMslAltitude |
hasMslAltitudeAccuracy
java-static fun hasMslAltitudeAccuracy(location: Location): Boolean
Returns true if the location has a Mean Sea Level altitude accuracy, false otherwise.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude accuracy does not exist. In order to allow for backwards compatibility and testing however, this method will return true if an extra value is with the key EXTRA_MSL_ALTITUDE_ACCURACY.
| See also | |
|---|---|
hasMslAltitudeAccuracy |
hasSpeedAccuracy
java-static fun hasSpeedAccuracy(location: Location): Boolean
Returns true if this location has a speed accuracy.
| See also | |
|---|---|
hasSpeedAccuracy |
hasVerticalAccuracy
java-static fun hasVerticalAccuracy(location: Location): Boolean
Returns true if this location has a vertical accuracy.
| See also | |
|---|---|
hasVerticalAccuracy |
isMock
java-static fun isMock(location: Location): Boolean
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 EXTRA_IS_MOCK and use the result to determine whether this should be considered a mock location.
| See also | |
|---|---|
LocationManager |
removeBearingAccuracy
java-static fun removeBearingAccuracy(location: Location): Unit
Removes the bearing accuracy from the location.
removeMslAltitude
java-static fun removeMslAltitude(location: Location): Unit
Removes the Mean Sea Level altitude from the location.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to remove any extra value with the key EXTRA_MSL_ALTITUDE.
| See also | |
|---|---|
removeMslAltitude |
removeMslAltitudeAccuracy
java-static fun removeMslAltitudeAccuracy(location: Location): Unit
Removes the Mean Sea Level altitude accuracy from the location.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude accuracy does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to remove any extra value with the key EXTRA_MSL_ALTITUDE_ACCURACY.
| See also | |
|---|---|
removeMslAltitudeAccuracy |
removeSpeedAccuracy
java-static fun removeSpeedAccuracy(location: Location): Unit
Removes the speed accuracy from the location.
removeVerticalAccuracy
java-static fun removeVerticalAccuracy(location: Location): Unit
Removes the vertical accuracy from the location.
setBearingAccuracyDegrees
java-static fun setBearingAccuracyDegrees(location: Location, bearingAccuracyD: Float): Unit
Set 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 set a float extra with the key EXTRA_BEARING_ACCURACY to include bearing accuracy. Be aware that this will overwrite any prior extra value under the same key.
| See also | |
|---|---|
setBearingAccuracyDegrees |
setMock
java-static fun setMock(location: Location, mock: Boolean): Unit
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 EXTRA_IS_MOCK to mark the location as mock. Be aware that this will overwrite any prior extra value under the same key.
setMslAltitudeAccuracyMeters
java-static fun setMslAltitudeAccuracyMeters(
location: Location,
mslAltitudeAccuracyMeters: @FloatRange(from = 0.0) Float
): Unit
Sets the Mean Sea Level altitude accuracy of the location in meters.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude accuracy does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to set a float extra with the key EXTRA_MSL_ALTITUDE_ACCURACY to include Mean Sea Level altitude accuracy. Be aware that this will overwrite any prior extra value under the same key.
| See also | |
|---|---|
setMslAltitudeAccuracyMeters |
setMslAltitudeMeters
java-static fun setMslAltitudeMeters(location: Location, mslAltitudeMeters: Double): Unit
Sets the Mean Sea Level altitude of the location in meters.
NOTE: On API levels below 34, the concept of Mean Sea Level altitude does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to set a double extra with the key EXTRA_MSL_ALTITUDE to include Mean Sea Level altitude. Be aware that this will overwrite any prior extra value under the same key.
| See also | |
|---|---|
setMslAltitudeMeters |
setSpeedAccuracyMetersPerSecond
java-static fun setSpeedAccuracyMetersPerSecond(
location: Location,
speedAccuracyMps: Float
): Unit
Set the estimated speed accuracy of this location in meters per second.
NOTE: On API levels below 26, the concept of speed accuracy does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to set a float extra with the key EXTRA_SPEED_ACCURACY to include speed accuracy. Be aware that this will overwrite any prior extra value under the same key.
| See also | |
|---|---|
setSpeedAccuracyMetersPerSecond |
setVerticalAccuracyMeters
java-static fun setVerticalAccuracyMeters(location: Location, verticalAccuracyM: Float): Unit
Set the estimated vertical accuracy of this location in meters.
NOTE: On API levels below 26, the concept of vertical accuracy does not exist. In order to allow for backwards compatibility and testing however, this method will attempt to set a float extra with the key EXTRA_VERTICAL_ACCURACY to include vertical accuracy. Be aware that this will overwrite any prior extra value under the same key.
| See also | |
|---|---|
setVerticalAccuracyMeters |