Position

@Serializable(with = PositionSerializer::class)
class Position : Iterable<Double> (source)

A Position is the fundamental geometry construct.

In JSON, a position is an array of numbers. There MUST be two or more elements. The first two elements are longitude and latitude, or easting and northing, precisely in that order using decimal numbers. Altitude or elevation MAY be included as an optional third element.

When serialized, the latitude, longitude, and altitude (if present) will be represented as an array.

Position(longitude = -75.0, latitude = 45.0)

Will be serialized as

[-75.0,45.0]

See RFC 7946 Section 3.1.1 for the full specification.

See also

PositionSerializer

Constructors

Link copied to clipboard
constructor(longitude: Double, latitude: Double)

Construct a Position with longitude and latitude.

constructor(longitude: Double, latitude: Double, altitude: Double)

Construct a Position with longitude, latitude, and altitude.

constructor(longitude: Double, latitude: Double, altitude: Double? = null)

Construct a Position with longitude, latitude, and optional altitude.

constructor(longitude: Double, latitude: Double, altitude: Double, vararg additionalElements: Double)

Construct a Position with more than the standard three axes (longitude, latitude, altitude).

Types

Link copied to clipboard
object Companion

Factory methods for creating and serializing Position objects.

Properties

Link copied to clipboard

Optionally, an altitude or elevation for this position in meters above or below the WGS84 reference ellipsoid.

Link copied to clipboard
@get:JvmName(name = "hasAltitude")
val hasAltitude: Boolean

Whether this position has an altitude component.

Link copied to clipboard

The latitude value of this position (or northing value for projected coordinates) in degrees.

Link copied to clipboard

The longitude value of this position (or easting value for projected coordinates) in degrees.

Link copied to clipboard
val size: Int

The number of elements in the coordinates array.

Functions

Link copied to clipboard
operator fun component1(): Double

Destructuring component for longitude.

Link copied to clipboard
operator fun component2(): Double

Destructuring component for latitude.

Link copied to clipboard
operator fun component3(): Double?

Destructuring component for altitude.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(index: Int): Double

Get the coordinate at the given index.

Link copied to clipboard
fun getOrNull(index: Int): Double?
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open operator override fun iterator(): Iterator<Double>
Link copied to clipboard
fun toJson(): String

Serialize this position to a JSON string.

Link copied to clipboard
open override fun toString(): String