Class: GeoDistance::Spherical
- Inherits:
-
DistanceFormula
- Object
- DistanceFormula
- GeoDistance::Spherical
- Defined in:
- lib/geo-distance/formula/spherical.rb
Class Method Summary collapse
Methods inherited from DistanceFormula
geo_distance, get_points, get_units, #initialize
Constructor Details
This class inherits a constructor from GeoDistance::DistanceFormula
Class Method Details
.distance(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/geo-distance/formula/spherical.rb', line 28 def self.distance *args from, to, units = get_points(args) return 0.0 if from == to #return 0.0 if points are have the same coordinates c = Math.acos( Math.sin(degrees_to_radians(from.lat)) * Math.sin(degrees_to_radians(to.lat)) + Math.cos(degrees_to_radians(from.lat)) * Math.cos(degrees_to_radians(to.lat)) * Math.cos(degrees_to_radians(to.lng) - degrees_to_radians(from.lng)) ).to_deg units ? c.radians_to(units) : c rescue Errno::EDOM 0.0 end |