Module: Geocoder
- Defined in:
- lib/geocoder.rb,
lib/geocoder/cli.rb,
lib/geocoder/sql.rb,
lib/geocoder/cache.rb,
lib/geocoder/query.rb,
lib/geocoder/lookup.rb,
lib/geocoder/railtie.rb,
lib/geocoder/request.rb,
lib/geocoder/version.rb,
lib/maxmind_database.rb,
lib/geocoder/exceptions.rb,
lib/geocoder/ip_address.rb,
lib/geocoder/models/base.rb,
lib/geocoder/stores/base.rb,
lib/geocoder/calculations.rb,
lib/geocoder/lookups/base.rb,
lib/geocoder/lookups/test.rb,
lib/geocoder/results/base.rb,
lib/geocoder/results/test.rb,
lib/geocoder/configuration.rb,
lib/geocoder/lookups/geoip2.rb,
lib/geocoder/models/mongoid.rb,
lib/geocoder/results/geoip2.rb,
lib/geocoder/models/mongo_base.rb,
lib/geocoder/configuration_hash.rb,
lib/geocoder/models/mongo_mapper.rb,
lib/geocoder/models/active_record.rb,
lib/geocoder/lookups/google_places_details.rb,
lib/geocoder/results/google_places_details.rb,
lib/generators/geocoder/config/config_generator.rb,
lib/generators/geocoder/maxmind/geolite_city_generator.rb,
lib/generators/geocoder/maxmind/geolite_country_generator.rb
Defined Under Namespace
Modules: Calculations, Generators, Lookup, MaxmindDatabase, Model, Request, Result, Sql, Store Classes: Cache, Cli, ConfigGenerator, Configuration, ConfigurationError, ConfigurationHash, Error, InvalidApiKey, InvalidRequest, IpAddress, OverQueryLimitError, Query, Railtie, RequestDenied
Constant Summary collapse
- VERSION =
"1.2.6"
Class Method Summary collapse
-
.address(query, options = {}) ⇒ Object
Look up the address of the given coordinates ([lat,lon]) or IP address (string).
-
.config ⇒ Object
Read-only access to the singleton’s config data.
-
.config_for_lookup(lookup_name) ⇒ Object
Read-only access to lookup-specific config data.
-
.configure(options = nil, &block) ⇒ Object
Configuration options should be set by passing a hash:.
-
.coordinates(address, options = {}) ⇒ Object
Look up the coordinates of the given street or IP address.
-
.search(query, options = {}) ⇒ Object
Search for information about an address or a set of coordinates.
Class Method Details
.address(query, options = {}) ⇒ Object
Look up the address of the given coordinates ([lat,lon]) or IP address (string).
36 37 38 39 40 |
# File 'lib/geocoder.rb', line 36 def self.address(query, = {}) if (results = search(query, )).size > 0 results.first.address end end |
.config ⇒ Object
Read-only access to the singleton’s config data.
25 26 27 |
# File 'lib/geocoder/configuration.rb', line 25 def self.config Configuration.instance.data end |
.config_for_lookup(lookup_name) ⇒ Object
Read-only access to lookup-specific config data.
32 33 34 35 36 37 38 39 |
# File 'lib/geocoder/configuration.rb', line 32 def self.config_for_lookup(lookup_name) data = config.clone data.reject!{ |key,value| !Configuration::OPTIONS.include?(key) } if config.has_key?(lookup_name) data.merge!(config[lookup_name]) end data end |
.configure(options = nil, &block) ⇒ Object
Configuration options should be set by passing a hash:
Geocoder.configure(
:timeout => 5,
:lookup => :yandex,
:api_key => "2a9fsa983jaslfj982fjasd",
:units => :km
)
16 17 18 19 20 |
# File 'lib/geocoder/configuration.rb', line 16 def self.configure( = nil, &block) if !.nil? Configuration.instance.configure() end end |
.coordinates(address, options = {}) ⇒ Object
Look up the coordinates of the given street or IP address.
26 27 28 29 30 |
# File 'lib/geocoder.rb', line 26 def self.coordinates(address, = {}) if (results = search(address, )).size > 0 results.first.coordinates end end |