Latitude
Latitude is a simple gem for calculating distances and headings between two geographic locations, using great circle math.
For now, this gem uses the WGS84 measurements for the shape of the earth.
Installation
Add this line to your application's Gemfile:
gem 'latitude'
And then execute:
$ bundle
Or install it yourself as:
$ gem install latitude
Usage
Note that coordinates are positive for N/E and negative for S/W.
Using Coordinate objects
A Coordinate
takes in a :latitude
and :longitude
in either decimal
or DMS format. For example,
coordinate = Coordinate.new(:latitude => "10 S",
:longitude => "9° 30′ E")
coordinate.latitdue #=> -10.0
coordinate.longitude #=> 9.5
Coordinate
s have multiple helper methods:
#great_circle_distance_to(final_coordinate)
calculates the great
circle distance between coordinates.
#initial_bearing_to(final_coordinate)
calculates the initial bearing
if traveling along a great circle route to another coordinate.
#final_bearing_to(initial_coordinate)
calculates the final bearing if
traveling along a great circle route from another coordinate.
Without Coordinate objects
Latitude.great_circle_distance(start_latitude, start_longitude, end_latitude,
end_longitude)
Calculates the great circle distance in kilometers between two coordinates.
Latitude.initial_heading(start_latitude, start_longitude, end_latitude, end_longitude)
Latitude.final_heading(start_latitude, start_longitude, end_latitude, end_longitude)
Calculates the initial and final headings if traveling between two points using a great circle path.
Contributing
- Fork it ( https://github.com/[my-github-username]/latitude/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request