Sha256: 5b7d342fc2f851a604c148ddf3036addfeb4855e71f4646eb5b0aa1b6d1220e1

Contents?: true

Size: 637 Bytes

Versions: 1

Compression:

Stored size: 637 Bytes

Contents

require 'geo-distance/core_ext'
require 'geo-distance/formula'

module GeoDistance
  class Spherical < DistanceFormula
    def self.distance( lat1, lon1, lat2, lon2) 
      from_longitude  = lon1.to_radians
      from_latitude   = lat1.to_radians
      to_longitude    = lon2.to_radians
      to_latitude     = lat2.to_radians

      c = Math.acos(
          Math.sin(from_latitude) *
          Math.sin(to_latitude) +

          Math.cos(from_latitude) * 
          Math.cos(to_latitude) *
          Math.cos(to_longitude - from_longitude)
      ) #* EARTH_RADIUS[units.to_sym]
      
      GeoDistance::Distance.new c
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geo-distance-0.1.2 lib/geo-distance/spherical.rb