geokit/latlng
Opaque LatLng (geographic coordinate) shared by every module
in geokit.
Latitudes are in degrees, in the range [-90, 90], with positive
values north of the equator. Longitudes are in degrees, in the
range [-180, 180], with positive values east of the prime
meridian. Out-of-range inputs to new return a typed
error; use wrap when your source data may be
denormalised (for example, sensor output that crosses the
antimeridian).
Types
Errors returned by new.
pub type LatLngError {
LatOutOfRange(lat: Float)
LngOutOfRange(lng: Float)
}
Constructors
-
LatOutOfRange(lat: Float)Latitude was outside
[-90, 90]. -
LngOutOfRange(lng: Float)Longitude was outside
[-180, 180].
Values
pub fn equal(a a: LatLng, b b: LatLng) -> Bool
Value equality. Two LatLng values are equal iff their lat and
lng components compare equal.
pub fn new(
lat lat: Float,
lng lng: Float,
) -> Result(LatLng, LatLngError)
Build a LatLng from latitude and longitude in degrees.
import geokit/latlng
let assert Ok(tokyo) = latlng.new(lat: 35.6812, lng: 139.7671)
pub fn wrap(lat lat: Float, lng lng: Float) -> LatLng
Build a LatLng, normalising longitude into [-180, 180] and
clamping latitude into [-90, 90]. Use this when the source data
may be denormalised (sensor output crossing the antimeridian,
great-circle calculations producing 181°, …).
import geokit/latlng
let p = latlng.wrap(lat: 91.0, lng: 181.0)
// p has lat = 90.0, lng = -179.0