class GeoDistance::DistanceFormula

Public Class Methods

geo_distance(*args) click to toggle source

use underlying distance formula

# File lib/geo-distance/formula.rb, line 13
def self.geo_distance *args
  GeoDistance.new distance(args), get_units(args.last_option)
end
get_points(*args) click to toggle source

used to convert various argument types into GeoPoints

# File lib/geo-distance/formula.rb, line 18
def self.get_points(*args)
  args.flatten!
  options = args.delete(args.last_option) || {}
  units = options[:units] || GeoDistance.default_units

  case args.size
  when 2
    [GeoPoint.new(args.first), GeoPoint.new(args.last), units]
  when 4
    [GeoPoint.new(args[0..1]), GeoPoint.new(args[2..3]), units]        
  else
    raise "Distance from point A to B, must be given either as 4 arguments (lat1, lng1, lat2, lng2) or 2 arguments: (pointA, pointB), was: #{args}"
  end
end
get_units(options = {}) click to toggle source

used to get the units for how to calculate the distance

# File lib/geo-distance/formula.rb, line 34
def self.get_units options = {}
  GeoUnits.key(options[:units] || :kms)
end
new() click to toggle source
# File lib/geo-distance/formula.rb, line 8
def initialize
  raise NotImplementedError
end