View Source HaversineEx (haversineEx v0.1.0)
Provides some helpers functions to calculate the distance between two points on Earth using the Haversine formula. Also can find the bearing between two points, and get a point at a given distance and bearing from a given point.
Link to this section Summary
Functions
Calculates the distance between all the points in the given list. The result is returned in the given unit (miles, meters, km).
Calculates the distance between two points on Earth using the Haversine formula. The result is returned in the given unit (miles, meters, km).
Calculates the bearing between two points.
Calculates a point at a given distance and bearing from a given point. The distance is given in the given unit (miles, meters, km).
Link to this section Functions
@spec distance([HaversineEx.Point.t()], atom()) :: number()
Calculates the distance between all the points in the given list. The result is returned in the given unit (miles, meters, km).
examples
Examples
iex> HaversineEx.distance([
...> %HaversineEx.Point{lat: 40.7767644, lng: -73.9761399},
...> %HaversineEx.Point{lat: 40.773987, lng: -73.971769},
...> %HaversineEx.Point{lat: 40.771209, lng: -73.9673991}
...> ], :miles)
0.597116937109039
@spec distance(HaversineEx.Point.t(), HaversineEx.Point.t(), atom()) :: number()
Calculates the distance between two points on Earth using the Haversine formula. The result is returned in the given unit (miles, meters, km).
examples
Examples
iex> HaversineEx.distance(%HaversineEx.Point{lat: 40.7767644, lng: -73.9761399}, %HaversineEx.Point{lat: 40.771209, lng: -73.9673991}, :miles)
0.5971169354600706
@spec find_bearing(HaversineEx.Point.t(), HaversineEx.Point.t()) :: number()
Calculates the bearing between two points.
examples
Examples
iex> HaversineEx.find_bearing(%HaversineEx.Point{lat: 40.7767644, lng: -73.9761399}, %HaversineEx.Point{lat: 40.771209, lng: -73.9673991})
130.0028272356484
@spec find_point(HaversineEx.Point.t(), number(), number(), atom()) :: %HaversineEx.Point{ lat: term(), lng: term() }
Calculates a point at a given distance and bearing from a given point. The distance is given in the given unit (miles, meters, km).
examples
Examples
iex> HaversineEx.find_point(%HaversineEx.Point{lat: 40.7767644, lng: -73.9761399}, 0.597117, 130.002827, :miles)
%HaversineEx.Point{lat: 40.77120899942672, lng: -73.96739909902514}