diff --git a/lib/geocoder.rb b/lib/geocoder.rb index bce5e65386998089502de32c3e8e49ceb1a1c011..46c810f09e10b405bba661830cc61f1ceb15e3da 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -227,25 +227,6 @@ module Geocoder fetch_coordinates(true) end - ## - # Query Google for the coordinates of the given phrase. - # Returns array [lat,lon] if found, nil if not found or if network error. - # - def self.fetch_coordinates(query) - return nil if query.blank? - return nil unless doc = self.search(query) - - # make sure search found a result - e = doc.elements['GeocodeResponse/status'] - return nil unless (e and e.text == "OK") - - # isolate the relevant part of the result - place = doc.elements['GeocodeResponse/result/geometry/location'] - - # blindly use the first results (assume they are most accurate) - ['lat', 'lng'].map{ |i| place.elements[i].text.to_f } - end - ## # Calculate the distance between two points on Earth (Haversine formula). # Takes two sets of coordinates and an options hash: @@ -337,6 +318,25 @@ module Geocoder end end + ## + # Query Google for the coordinates of the given phrase. + # Returns array [lat,lon] if found, nil if not found or if network error. + # + def self.fetch_coordinates(query) + return nil if query.blank? + return nil unless doc = self.search(query) + + # make sure search found a result + e = doc.elements['GeocodeResponse/status'] + return nil unless (e and e.text == "OK") + + # isolate the relevant part of the result + place = doc.elements['GeocodeResponse/result/geometry/location'] + + # blindly use the first results (assume they are most accurate) + ['lat', 'lng'].map{ |i| place.elements[i].text.to_f } + end + ## # Request an XML geo search result from Google. # This method is not intended for general use (prefer Geocoder.search).