Module: Geocoder

Defined in:
lib/geocoder.rb,
lib/geocoder/cli.rb,
lib/geocoder/sql.rb,
lib/geocoder/util.rb,
lib/geocoder/cache.rb,
lib/geocoder/query.rb,
lib/geocoder/logger.rb,
lib/geocoder/lookup.rb,
lib/easting_northing.rb,
lib/geocoder/railtie.rb,
lib/geocoder/request.rb,
lib/geocoder/version.rb,
lib/maxmind_database.rb,
lib/geocoder/esri_token.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/kernel_logger.rb,
lib/geocoder/lookups/geoip2.rb,
lib/geocoder/models/mongoid.rb,
lib/geocoder/results/geoip2.rb,
lib/geocoder/lookups/geoapify.rb,
lib/geocoder/results/geoapify.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/results/abstract_api.rb,
lib/geocoder/lookups/geoportail_lu.rb,
lib/geocoder/results/ipqualityscore.rb,
lib/geocoder/lookups/ip2location_lite.rb,
lib/generators/geocoder/migration_version.rb,
lib/geocoder/lookups/google_places_search.rb,
lib/geocoder/results/google_places_search.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: CacheStore, Calculations, Generators, Lookup, MaxmindDatabase, Model, Request, Result, Sql, Store, Util Classes: Cache, Cli, ConfigGenerator, Configuration, ConfigurationError, ConfigurationHash, EastingNorthing, Error, EsriToken, InvalidApiKey, InvalidRequest, IpAddress, KernelLogger, Logger, LookupTimeout, NetworkError, OverQueryLimitError, Query, Railtie, RequestDenied, ResponseParseError, ServiceUnavailable

Constant Summary collapse

VERSION =
"1.8.5"

Class Method Summary collapse

Class Method Details

.address(query, options = {}) ⇒ Object

Look up the address of the given coordinates ([lat,lon]) or IP address (string).



38
39
40
41
42
# File 'lib/geocoder.rb', line 38

def self.address(query, options = {})
  if (results = search(query, options)).size > 0
    results.first.address
  end
end

.configObject

Read-only access to the singleton’s config data.



26
27
28
# File 'lib/geocoder/configuration.rb', line 26

def self.config
  Configuration.instance.data
end

.config_for_lookup(lookup_name) ⇒ Object

Read-only access to lookup-specific config data.



33
34
35
36
37
38
39
40
# File 'lib/geocoder/configuration.rb', line 33

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
)


17
18
19
20
21
# File 'lib/geocoder/configuration.rb', line 17

def self.configure(options = nil, &block)
  if !options.nil?
    Configuration.instance.configure(options)
  end
end

.coordinates(address, options = {}) ⇒ Object

Look up the coordinates of the given street or IP address.



28
29
30
31
32
# File 'lib/geocoder.rb', line 28

def self.coordinates(address, options = {})
  if (results = search(address, options)).size > 0
    results.first.coordinates
  end
end

.log(level, message) ⇒ Object



5
6
7
# File 'lib/geocoder/logger.rb', line 5

def self.log(level, message)
  Logger.instance.log(level, message)
end

.merge_into_lookup_config(lookup_name, options) ⇒ Object

Merge the given hash into a lookup’s existing configuration.



45
46
47
48
# File 'lib/geocoder/configuration.rb', line 45

def self.merge_into_lookup_config(lookup_name, options)
  base = Geocoder.config[lookup_name]
  Geocoder.configure(lookup_name => base.merge(options))
end

.search(query, options = {}) ⇒ Object

Search for information about an address or a set of coordinates.



20
21
22
23
# File 'lib/geocoder.rb', line 20

def self.search(query, options = {})
  query = Geocoder::Query.new(query, options) unless query.is_a?(Geocoder::Query)
  query.blank? ? [] : query.execute
end