0.01
No commit activity in last 3 years
No release in over 3 years
Haversine calculation written in Ruby that supports both distances in miles and kilometers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
>= 0
>= 0
 Project Readme

FastHaversine

Gem Version Build Status Dependency Status Code Climate

Haversine calculation written in Ruby that supports distances calculations in both miles and kilometers

Installation

Add this line to your application's Gemfile:

gem 'fast_haversine'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fast_haversine

Usage

For kilometers:

distance = FastHaversine.distance_between([lat1, lon1], [lat2, lon2], :km)

For miles:

distance = FastHaversine.distance_between([lat1, lon1], [lat2, lon2], :mi)

Benchmark

During specs, I ran the following benchmark:

1_000_000.times { FastHaversine.distance_between(sf, chi, :mi) }

0.700000   0.000000   0.700000 (  0.700143)

This is much faster than a common ruby implementation:

1_000_000.times do
  RubyHaversine.distance_between(
    [37.7833, -122.4167],
    [41.8819, -87.6278],
    units: :mi
  )
end

7.510000   0.320000   7.830000 (  7.930863)

Contributing

  1. Fork it ( https://github.com/paulnsorensen/fast_haversine/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request