geokit

Ruby On Rails Geokit gem geocoding returning nil


I am struggling with using the geokit gem in a Ruby on Rails application when supplied with an address to return anything other than nil.

I've read the previous articles here on Stack Overflow, the GitHub repo for the gem and other internet articles and I believe that I am following the examples.

This is code from my terminal window where I placed a binding.pry in my controller.rb file

    20:
    21:   location_a = Geokit::Geocoders::GoogleGeocoder.geocode("140 Market St, San Francisco, CA")
    22:   location_b = GoogleGeocoder.geocode("140 Market St, San Francisco, CA")
    23:
 => 24:   binding.pry
    25:
    26: end

[1] pry(#<BrewsController>)> location_a
=> #<Geokit::GeoLoc:0x00007fa0d659f208
 @all=[#<Geokit::GeoLoc:0x00007fa0d659f208 ...>],
 @city=nil,
 @country_code=nil,
 @full_address=nil,
 @lat=nil,
 @lng=nil,

I read to put these at the top of my controller.rb file:

  require 'geokit'
  include Geokit::Geocoders

I have these lines of code in the config/initializers/geokit_config.rb file:

Geokit::Geocoders::GoogleGeocoder.api_key = "my-key-I-will-not-put-here"
Geokit::Geocoders::provider_order = [:google]

I have the gems installed:

/Users/slathyd/.gem/ruby/2.4.5/gems/geokit-1.13.1
/Users/slathyd/.gem/ruby/2.4.5/gems/geokit-rails-2.3.1

This is my Gemfile

gem 'geokit'
gem 'geokit-rails'

If anyone could tell me what I'm doing wrong and how to fix it, I would greatly appreciate it. Cheers.


Solution

  • The way I got the code to work was to simply restart everything. I had restarted my server several times, but I must have had to do something else. I shut it all down, the laptop, restarted the entire machine and it worked and has been working since. Thank you for all of those who looked at this and did research.