Search code examples
ruby-on-railsgeokit

Gem GeoKit: uninitialized constant GeoKit::Geocoders::Geocoder when trying to initialize my own geocoder


I followed the instructions on installing geokit-rails (v 2.0.1) and geokit (v 1.8.5). Then attempted to create my own geocoder (to be used with tests). Here is the code I use in my config/initializers/fake_geocoder.rb file

require 'geokit'

module GeoKit
  module Geocoders
    class FakeGeocoder < Geocoder
      #to use, include :fake in the list of geocoders
      private

      def self.do_geocode(location, options = {})
          geocode_payload = GeoKit::GeoLoc.new(:lat => 123.456, :lng => 123.456)  
          geocode_payload.success = true 
          return geocode_payload
      end
    end
  end
end

When attempting to start up the rails console (bundle exec rails c), I get the following error:

../config/initializers/fake_geocoder.rb:6:in    `<module:Geocoders>': uninitialized constant GeoKit::Geocoders::Geocoder (NameError)
from ../config/initializers/fake_geocoder.rb:5:in `<module:GeoKit>'
from ../config/initializers/fake_geocoder.rb:4:in `<top (required)>'

Any advice you can provide as to why it can't find the Geocoder class would be greatly appreciated.


Solution

  • For a while Geokit and GeoKit (capital K) worked. 1.7.1 removed GeoKit.

    Simply replace any reference to GeoKit with Geokit

    I'm the maintainer of Geokit so if there's any README's that are out of date (I couldn't see any) please let me know.