Sha256: 14b2c7a3882da2fb02f87ebdace86765429caf4dc640fd5864250d88904697a3

Contents?: true

Size: 582 Bytes

Versions: 3

Compression:

Stored size: 582 Bytes

Contents

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

class GeoDistance
  class Flat < DistanceFormula

    # Calculate distance using Flat earth formula, returns distance in whatever unit is specified (kms by default)
    def self.distance *args
      from, to, units = get_points(args)

      return 0 if from == to # return 0.0 if points are have the same coordinates      

      Math.sqrt(
        (units_per_latitude_degree(units) * (from.lat - to.lat))**2 +
        (units_per_longitude_degree(from.lat, units) * (from.lng - to.lng))**2
      )
    end
  end
end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geo-distance-0.2.2 lib/geo-distance/formula/flat.rb
geo-distance-0.2.1 lib/geo-distance/formula/flat.rb
geo-distance-0.2.0 lib/geo-distance/formula/flat.rb