Haversine (haversine v0.1.0) View Source

Calculate great circle distances (shortest travel distance on the surface of a spherical Earth) given a two longitude-latitude pairs. This is an implementation of the Haversine formula

Link to this section Summary

Functions

Returns the great circle distance in meters along a linestring defined by the list of {longitude, latitude} pairs.

Returns the great circle distance in meters between two points in the form of {longitude, latitude}.

Link to this section Types

Specs

coordinates() :: {float(), float()}

Link to this section Functions

Specs

distance([coordinates()]) :: float()

Returns the great circle distance in meters along a linestring defined by the list of {longitude, latitude} pairs.

Examples

iex> Haversine.distance([
...>  {-96.796667, 32.775833},
...>  {126.967583, 37.566776},
...>  {151.215158, -33.857406},
...>  {55.274180, 25.197229},
...>  {6.942661, 50.334057},
...>  {-97.635926, 30.134442}])
44728827.84910634

iex> Haversine.distance([])
0.0

iex> Haversine.distance([{-96.796667, 32.775833}])
0.0

Specs

distance(coordinates(), coordinates()) :: float()

Returns the great circle distance in meters between two points in the form of {longitude, latitude}.

Examples

iex> Haversine.distance({-105.343, 39.984}, {-105.534, 39.123})
97129.22118967834

iex> Haversine.distance({-74.00597, 40.71427}, {-70.56656, -33.42628})
8251609.780264794