Class: Grobi::Maps
- Inherits:
-
Object
- Object
- Grobi::Maps
- Defined in:
- lib/grobi/maps.rb
Instance Method Summary collapse
- #google ⇒ Object
-
#initialize(client) ⇒ Maps
constructor
A new instance of Maps.
- #parse(s) ⇒ Object
-
#search(address, ops = {}) ⇒ Object
options :language (en, zh-TW, etc.).
Constructor Details
#initialize(client) ⇒ Maps
Returns a new instance of Maps.
5 6 7 |
# File 'lib/grobi/maps.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#google ⇒ Object
32 33 34 |
# File 'lib/grobi/maps.rb', line 32 def google return @client end |
#parse(s) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/grobi/maps.rb', line 22 def parse(s) j = JSON.parse(s) if (j['status'] == "OK") placemarks = j['results'] placemarks.collect { |p| Placemark.new(p) } if placemarks else nil end end |
#search(address, ops = {}) ⇒ Object
options :language (en, zh-TW, etc.)
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/grobi/maps.rb', line 11 def search(address, ops={}) href='http://maps.googleapis.com/maps/api/geocode/json' conn = Faraday.new response = conn.get href do |req| req.params['address'] = address req.params['sensor'] = 'false' req.params['language'] = ops[:language] if ops[:language] end parse(response.body) end |