SphericalUtil

Distances, headings, offsets, interpolation and areas on the Earth as a sphere, e.g. to move a vehicle marker along its route and turn it the way it travels.

The methods have the names, parameters and units of SphericalUtil in android-maps-utils, so code using it only needs another import. Distances are in meters, headings in degrees clockwise from north, between -180 and 180.

Example:

val heading = SphericalUtil.computeHeading(from, to)
marker.position = SphericalUtil.interpolate(from, to, fraction)
marker.rotation = heading.toFloat()

Properties

Link copied to clipboard
const val EARTH_RADIUS: Double = 6371009.0

The mean radius of the Earth in meters, as in android-maps-utils.

Functions

Link copied to clipboard

Returns the area of a closed path in square meters, 0 for fewer than 3 points.

Link copied to clipboard

Returns the great-circle distance between two locations in meters.

Link copied to clipboard

Returns the heading from one location to another, in degrees clockwise from north, between -180 and 180: 0 is north, 90 east, -90 west and -180 south.

Link copied to clipboard

Returns the length of a path in meters, 0 for fewer than 2 points.

Link copied to clipboard
fun computeOffset(from: LatLng, distance: Double, heading: Double): LatLng

Returns the location reached by going distance meters from from at heading degrees clockwise from north, along the great circle.

Link copied to clipboard
fun computeOffsetOrigin(to: LatLng, distance: Double, heading: Double): LatLng?

Returns the location from which going distance meters at heading degrees reaches to, the inverse of computeOffset, or null if there is none.

Link copied to clipboard

Returns the signed area of a closed path in square meters: positive if the points go counter-clockwise, negative if clockwise, 0 for fewer than 3 points.

Link copied to clipboard
fun interpolate(from: LatLng, to: LatLng, fraction: Double): LatLng

Returns the location at fraction of the way from from to to along the great circle: 0 is from, 1 is to. Crossing the 180th meridian goes the short way.