Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/location/altitude/AltitudeConverter#pubctors) \| [Methods](https://developer.android.com/reference/android/location/altitude/AltitudeConverter#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/location/altitude/AltitudeConverter#inhmethods)

# AltitudeConverter

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/location/altitude/AltitudeConverter "View this page in Kotlin") \|Java


`
public

final

class
AltitudeConverter
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.location.altitude.AltitudeConverter |

<br />

*** ** * ** ***

Converts altitudes reported above the World Geodetic System 1984 (WGS84) reference ellipsoid
into ones above Mean Sea Level.

Reference:

```
 Brian Julian and Michael Angermann.
 "Resource efficient and accurate altitude conversion to Mean Sea Level."
 2023 IEEE/ION Position, Location and Navigation Symposium (PLANS).
 
```

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/location/altitude/AltitudeConverter#AltitudeConverter()() ` Creates an instance that manages an independent cache to optimized conversions of locations in proximity to one another. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/location/altitude/AltitudeConverter#addMslAltitudeToLocation(android.content.Context,%20android.location.Location)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/location/Location location) ` Adds a Mean Sea Level altitude to the `location`. |
| ` boolean` | ` https://developer.android.com/reference/android/location/altitude/AltitudeConverter#tryAddMslAltitudeToLocation(android.location.Location)(https://developer.android.com/reference/android/location/Location location) ` Same as `https://developer.android.com/reference/android/location/altitude/AltitudeConverter#addMslAltitudeToLocation(android.content.Context,%20android.location.Location)` except that this method can be called on the main thread as data will not be loaded from raw assets. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### AltitudeConverter

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AltitudeConverter ()
```

Creates an instance that manages an independent cache to optimized conversions of locations
in proximity to one another.

<br />

## Public methods

### addMslAltitudeToLocation

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addMslAltitudeToLocation (Context context, 
                Location location)
```

Adds a Mean Sea Level altitude to the `location`. In addition, adds a Mean Sea Level
altitude accuracy if the `location` has a finite and non-negative vertical accuracy;
otherwise, does not add a corresponding accuracy.

Must be called off the main thread as data may be loaded from raw assets.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: This value cannot be `null`. <br /> |
| `location` | `Location`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs when loading data from raw assets. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the `location` has an invalid latitude, longitude, or altitude above WGS84. Specifically, the latitude must be between -90 and 90 (both inclusive), the longitude must be between -180 and 180 (both inclusive), and the altitude above WGS84 must be finite. |

### tryAddMslAltitudeToLocation

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean tryAddMslAltitudeToLocation (Location location)
```

Same as `https://developer.android.com/reference/android/location/altitude/AltitudeConverter#addMslAltitudeToLocation(android.content.Context,%20android.location.Location)` except that this method can be
called on the main thread as data will not be loaded from raw assets. Returns true if a Mean
Sea Level altitude is added to the `location`; otherwise, returns false and leaves the
`location` unchanged.

Prior calls to `https://developer.android.com/reference/android/location/altitude/AltitudeConverter#addMslAltitudeToLocation(android.content.Context,%20android.location.Location)` off the main thread
are necessary to load data from raw assets. Example code on the main thread is as follows:

    if (!mAltitudeConverter.tryAddMslAltitudeToLocation(location)) {
           // Queue up only one call off the main thread.
           if (mIsAltitudeConverterIdle) {
               mIsAltitudeConverterIdle = false;
               executeOffMainThread(() -> {
                   try {
                       // Load raw assets for next call attempt on main thread.
                       mAltitudeConverter.addMslAltitudeToLocation(mContext, location);
                   } catch (IOException e) {
                       Log.e(TAG, "Not loading raw assets: " + e);
                   }
                   mIsAltitudeConverterIdle = true;
               });
           }
       }
     
<br />

<br />

| Parameters ||
|---|---|
| `location` | `Location`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |