Class: Google::Geocode
- Inherits:
-
Object
- Object
- Google::Geocode
- Defined in:
- lib/google/geocode.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #do_geocode(location) ⇒ Object
- #geocode(location) ⇒ Object
-
#initialize(api_key, client) ⇒ Geocode
constructor
A new instance of Geocode.
- #reverse_geocode(location) ⇒ Object
Constructor Details
#initialize(api_key, client) ⇒ Geocode
Returns a new instance of Geocode.
7 8 9 10 |
# File 'lib/google/geocode.rb', line 7 def initialize(api_key, client) @api_key = api_key @client = client end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/google/geocode.rb', line 6 def api_key @api_key end |
Instance Method Details
#do_geocode(location) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/google/geocode.rb', line 12 def do_geocode(location) url = "http://maps.google.com/maps/geo?sensor=false&key=#{@api_key}&output=json&q=#{location}&client=#{@client}" resp = Net::HTTP.get_response(URI.parse(url)) data = resp.body Google::Result.new(data) end |
#geocode(location) ⇒ Object
20 21 22 23 |
# File 'lib/google/geocode.rb', line 20 def geocode(location) # change whitespace to %20 for the URL result = do_geocode location.gsub(/\s+/, '%20') end |
#reverse_geocode(location) ⇒ Object
26 27 28 29 |
# File 'lib/google/geocode.rb', line 26 def reverse_geocode(location) # reverse geocodes should not have any spaces in them result = do_geocode location.gsub(/\s+/, '') end |