Class: Geokit::Geocoders::GeonamesGeocoder

Inherits:
Geocoder
  • Object
show all
Defined in:
lib/geokit/geocoders.rb

Overview

Another geocoding web service www.geonames.org

Class Method Summary collapse

Methods inherited from Geocoder

call_geocoder_service, do_reverse_geocode, geocode, reverse_geocode

Class Method Details

.cities_in_bounds(bounds) ⇒ Object



371
372
373
374
375
# File 'lib/geokit/geocoders.rb', line 371

def self.cities_in_bounds(bounds)
  params = "/cities?north=#{bounds.ne.lat}&south=#{bounds.sw.lat}&east=#{bounds.ne.lng}&west=#{bounds.sw.lng}"

  do_call_geocoder_service(bounds.to_s, params)
end

.find_nearby(ll, options) ⇒ Object



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/geokit/geocoders.rb', line 377

def self.find_nearby(ll, options)
  params = "/findNearby?lat=#{ll.lat}&lng=#{ll.lng}"

  params << "&radius=#{options[:radius]}" if options[:radius]

  if options[:feature_class]
    Array(options[:feature_class]).each do |fc|
      params << "&featureClass=#{fc}"
    end
  end
  if options[:feature_code]
    Array(options[:feature_code]).each do |fc|
      params << "&featureCode=#{fc}"
    end
  end
  params << "&style=FULL"
  params << "&maxRows=1"

  do_call_geocoder_service(ll.to_s, params)
end

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

Returns result from geonames’ search webservice



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/geokit/geocoders.rb', line 340

def self.search(address, options = {})
  params = "/search?q=#{Geokit::Inflector::url_escape(address_string(address))}"

  if options[:continent]
    Array(options[:continent]).each do |c|
      params << "&continentCode=#{c}"
    end
  end

  if options[:feature_class]
    Array(options[:feature_class]).each do |fc|
      params << "&featureClass=#{fc}"
    end
  end

  if options[:feature_code]
    Array(options[:feature_code]).each do |fc|
      params << "&featureCode=#{fc}"
    end
  end

  if options[:operator].to_s.upcase == 'OR'
    params << "&operator=OR"
  end

  params << "&style=FULL"
  params << "&maxRows=1"

  do_call_geocoder_service(address, params)
end