Skip to content
Snippets Groups Projects
Commit 8ffaede5 authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge branch 'master' of git://github.com/vanboom/geocoder into vanboom-master

parents d14f68c7 49f73728
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ module Geocoder
# Conversion factor: multiply by kilometers to get miles.
#
KM_IN_MI = 0.621371192
KM_IN_NM = 0.540
# Not a number constant
NAN = defined?(::Float::NAN) ? ::Float::NAN : 0 / 0.0
......@@ -263,13 +264,27 @@ module Geocoder
km * km_in_mi
end
##
# Convert kilometers to nautical miles.
#
def to_nauticalmiles(km)
km * km_in_nm
end
##
# Radius of the Earth in the given units (:mi or :km).
# Use Geocoder.configure(:units => ...) to configure default units.
#
def earth_radius(units = nil)
units ||= Geocoder.config.units
units == :km ? EARTH_RADIUS : to_miles(EARTH_RADIUS)
case units
when :km
EARTH_RADIUS
when :mi
to_miles(EARTH_RADIUS)
when :nm
to_nauticalmiles(EARTH_RADIUS)
end
end
##
......@@ -279,6 +294,15 @@ module Geocoder
KM_IN_MI
end
##
# Conversion factor: km to nm.
#
def km_in_nm
KM_IN_NM
end
##
# Conversion factor: mi to km.
#
......@@ -286,6 +310,13 @@ module Geocoder
1.0 / KM_IN_MI
end
##
# Conversion factor: nm to km.
#
def nm_in_km
1.0 / KM_IN_NM
end
##
# Takes an object which is a [lat,lon] array, a geocodable string,
# or an object that implements +to_coordinates+ and returns a
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment