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

Code cleanup: move method down several lines.

parent 6b590f00
No related branches found
No related tags found
No related merge requests found
......@@ -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).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment