Class: Graticule::Geocoder::SimpleGeo

Inherits:
Base
  • Object
show all
Defined in:
lib/graticule/geocoder/simple_geo.rb

Overview

First you need a SimpleGeo JSONP API key. You can register for one here: simplegeo.com/docs/clients-code-libraries/javascript-sdk

gg = Graticule.service(:SimpleGeo).new(SIMPLEGEO_TOKEN)
location = gg.locate '1600 Amphitheater Pkwy, Mountain View, CA'
location.coordinates
#=> [37.423111, -122.081783]

Constant Summary

Constants inherited from Base

Base::USER_AGENT

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ SimpleGeo

Returns a new instance of SimpleGeo.


17
18
19
20
# File 'lib/graticule/geocoder/simple_geo.rb', line 17

def initialize(token)
  @token  = token
  @url    = URI.parse 'http://api.simplegeo.com/1.0/context/address.json?'
end

Instance Method Details

#locate(query) ⇒ Object


22
23
24
# File 'lib/graticule/geocoder/simple_geo.rb', line 22

def locate(query)
  get :address => "#{query}"
end

#time_zone(query) ⇒ Object

reimplement Base#get so we can return only the time zone for replacing geonames


27
28
29
30
31
32
33
34
# File 'lib/graticule/geocoder/simple_geo.rb', line 27

def time_zone(query)
  response = prepare_response(make_url(:address => "#{query}").open('User-Agent' => USER_AGENT).read)
  check_error(response)
  return parse_time_zone(response)
rescue OpenURI::HTTPError => e
  check_error(prepare_response(e.io.read))
  raise
end