Haversine – geo distance calculations

Calculates the haversine distance between two locations using longitude and latitude. This is done using Math formulas without resorting to Active Record or SQL DB functionality

This is meant to ba a replacement for all those geocode and geolocation utils out there that use built in SQL DB functionality for their calculations!

Install & Usage

require 'haversine'

it "should work" do
  lon1 = -104.88544
  lat1 = 39.06546

  lon2 = -104.80
  lat2 = lat1

  dist = Haversine.distance( lat1, lon1, lat2, lon2 )

  puts "the distance from  #{lat1}, #{lon1} to #{lat2}, #{lon2} is: #{dist[:meters].number} meters"

  puts "#{dist[:feet]}"
  puts "#{dist.meters}"
  puts "#{dist[:km]}"
  puts "#{dist[:miles]}"
  dist[:km].to_s.should match(/7\.376*/)
end  

Note: Haversine is used in the geo_magic gem

Contributing to haversine

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2011 Kristian Mandrup. See LICENSE.txt for further details.