diff --git a/lib/geocoder/calculations.rb b/lib/geocoder/calculations.rb index c36e59329ea2fd7a58ac45b8675763a5bb1b2322..84ab009c872f793fc565559bb1acf1892044070f 100644 --- a/lib/geocoder/calculations.rb +++ b/lib/geocoder/calculations.rb @@ -42,7 +42,12 @@ module Geocoder # Returns true if all given arguments are valid latitude/longitude values. # def coordinates_present?(*args) - args.all? { |a| a.is_a? Numeric and !a.to_f.nan? } + args.each do |a| + # note that Float::NAN != Float::NAN + # still, this could probably be improved: + return false if (!a.is_a?(Numeric) or a.to_s == "NaN") + end + true end ## @@ -392,8 +397,13 @@ module Geocoder def extract_coordinates(point) case point when Array - if point.size == 2 and coordinates_present?(*point) - return point.map {|coords| coords.to_f} + if point.size == 2 + lat, lon = point + if !lat.nil? && lat.respond_to?(:to_f) and + !lon.nil? && lon.respond_to?(:to_f) + then + return [ lat.to_f, lon.to_f ] + end end when String point = Geocoder.coordinates(point) and return point