Module: Geocoder
- Extended by:
- Geocoder
- Included in:
- Geocoder
- Defined in:
- lib/geocoder.rb,
lib/geocoder/cache.rb,
lib/geocoder/railtie.rb,
lib/geocoder/request.rb,
lib/geocoder/orms/base.rb,
lib/geocoder/calculations.rb,
lib/geocoder/lookups/base.rb,
lib/geocoder/results/base.rb,
lib/geocoder/configuration.rb
Defined Under Namespace
Modules: Calculations, Lookup, ModelMethods, Orm, Request, Result Classes: Cache, Configuration, ConfigurationError, Error, Railtie
Instance Method Summary collapse
-
#address(latitude, longitude) ⇒ Object
Look up the address of the given coordinates.
-
#cache ⇒ Object
The working Cache object, or
nil
if none configured. -
#coordinates(address) ⇒ Object
Look up the coordinates of the given street or IP address.
-
#search(*args) ⇒ Object
Search for information about an address or a set of coordinates.
Instance Method Details
#address(latitude, longitude) ⇒ Object
Look up the address of the given coordinates.
49 50 51 52 53 |
# File 'lib/geocoder.rb', line 49 def address(latitude, longitude) if (results = search(latitude, longitude)).size > 0 results.first.address end end |
#cache ⇒ Object
The working Cache object, or nil
if none configured.
58 59 60 61 62 63 |
# File 'lib/geocoder.rb', line 58 def cache if @cache.nil? and store = Configuration.cache @cache = Cache.new(store, Configuration.cache_prefix) end @cache end |
#coordinates(address) ⇒ Object
Look up the coordinates of the given street or IP address.
40 41 42 43 44 |
# File 'lib/geocoder.rb', line 40 def coordinates(address) if (results = search(address)).size > 0 results.first.coordinates end end |
#search(*args) ⇒ Object
Search for information about an address or a set of coordinates.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/geocoder.rb', line 13 def search(*args) if blank_query?(args[0]) results = [] else ip = (args.size == 1 and ip_address?(args.first)) results = lookup(ip).search(*args) end results.instance_eval do def warn_search_deprecation(attr) warn "DEPRECATION WARNING: Geocoder.search now returns an array of Geocoder::Result objects. " + "Calling '%s' directly on the returned array will cause an exception in Geocoder v1.0." % attr end def coordinates; warn_search_deprecation('coordinates'); first.coordinates if first; end def latitude; warn_search_deprecation('latitude'); first.latitude if first; end def longitude; warn_search_deprecation('longitude'); first.longitude if first; end def address; warn_search_deprecation('address'); first.address if first; end def city; warn_search_deprecation('city'); first.city if first; end def country; warn_search_deprecation('country'); first.country if first; end def country_code; warn_search_deprecation('country_code'); first.country_code if first; end end return results end |