Class: GeoMagic::GeocodeAdapter

Inherits:
GeoAdapter show all
Defined in:
lib/geo_magic/geocode/geocode_adapter.rb

Defined Under Namespace

Modules: GeocodeAPI

Instance Attribute Summary

Attributes inherited from GeoAdapter

#environment, #service_name

Instance Method Summary collapse

Methods inherited from GeoAdapter

#get_key, #get_service, #setup

Constructor Details

#initialize(service_name = :google, env = :default) ⇒ GeocodeAdapter

Returns a new instance of GeocodeAdapter.



5
6
7
# File 'lib/geo_magic/geocode/geocode_adapter.rb', line 5

def initialize service_name = :google, env = :default
  super      
end

Instance Method Details

#geocode(location_str) ⇒ Object



14
15
16
17
18
19
# File 'lib/geo_magic/geocode/geocode_adapter.rb', line 14

def geocode location_str
  result = geo_coder.geocode(CGI.escape(location_str)).extend GeocodeAPI
  # p result.data['Status']
  raise GeoMagic::GeoCodeError if result.data['Status']['code'] != 200
  result
end

#instanceObject



9
10
11
12
# File 'lib/geo_magic/geocode/geocode_adapter.rb', line 9

def instance
  @geo_coder ||= ::Geocode.new_geocoder service_name, {:google_api_key => google_key}      
  self
end

#reverse_geocode(latitude, longitude) ⇒ Object



123
124
125
# File 'lib/geo_magic/geocode/geocode_adapter.rb', line 123

def reverse_geocode latitude, longitude
  geo_coder.reverse_geocode "#{latitude}, #{longitude}"
end