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

# GeomagneticField

*** ** * ** ***

` public class GeomagneticField `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.GeomagneticField |

<br />

*** ** * ** ***

Estimates magnetic field at a given point on Earth, and in particular, to compute the magnetic declination from true north.

This uses the World Magnetic Model produced by the United States National Geospatial-Intelligence Agency. More details about the model can be found at <http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml>. This class currently uses WMM-2020 which is valid until 2025, but should produce acceptable results for several years after that. Future versions of Android may use a newer version of the model.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/hardware/GeomagneticField#GeomagneticField(float,%20float,%20float,%20long)(float gdLatitudeDeg, float gdLongitudeDeg, float altitudeMeters, long timeMillis) ` Estimate the magnetic field at a given point and time. |

| ### Public methods ||
|---|---|
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getDeclination()() ` |
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getFieldStrength()() ` |
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getHorizontalStrength()() ` |
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getInclination()() ` |
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getX()() ` |
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getY()() ` |
| ` float` | ` https://developer.android.com/reference/android/hardware/GeomagneticField#getZ()() ` |

### 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

### GeomagneticField

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

```
public GeomagneticField (float gdLatitudeDeg, 
                float gdLongitudeDeg, 
                float altitudeMeters, 
                long timeMillis)
```

Estimate the magnetic field at a given point and time.

<br />

| Parameters ||
|---|---|
| `gdLatitudeDeg` | `float`: Latitude in WGS84 geodetic coordinates -- positive is east. <br /> |
| `gdLongitudeDeg` | `float`: Longitude in WGS84 geodetic coordinates -- positive is north. <br /> |
| `altitudeMeters` | `float`: Altitude in WGS84 geodetic coordinates, in meters. <br /> |
| `timeMillis` | `long`: Time at which to evaluate the declination, in milliseconds since January 1, 1970. (approximate is fine -- the declination changes very slowly). <br /> |

## Public methods

### getDeclination

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

```
public float getDeclination ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | The declination of the horizontal component of the magnetic field from true north, in degrees (i.e. positive means the magnetic field is rotated east that much from true north). <br /> |

### getFieldStrength

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

```
public float getFieldStrength ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | Total field strength in nanoteslas. <br /> |

### getHorizontalStrength

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

```
public float getHorizontalStrength ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | Horizontal component of the field strength in nanoteslas. <br /> |

### getInclination

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

```
public float getInclination ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | The inclination of the magnetic field in degrees -- positive means the magnetic field is rotated downwards. <br /> |

### getX

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

```
public float getX ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | The X (northward) component of the magnetic field in nanoteslas. <br /> |

### getY

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

```
public float getY ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | The Y (eastward) component of the magnetic field in nanoteslas. <br /> |

### getZ

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

```
public float getZ ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | The Z (downward) component of the magnetic field in nanoteslas. <br /> |