I am trying to get the address when inputting coordinates like so in my model.
def full_address
Geocoder.address("#{self.latlon.x}, #{self.latlon.y}")
end
However, sometimes it works perfectly fine and then sometimes i get this error. I've looked all over for a solution but none is applicable to me.
warning: constant Geokit::Geocoders::Geocoder::TimeoutError is deprecated
E, [2016-11-15T17:06:32.828481 #7406] ERROR -- : Caught an error during Google geocoding call: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A
E, [2016-11-15T17:06:32.828665 #7406] ERROR -- : /Users/Brandon/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock'
I wasn't going to comment but no one has posted anything. Since your particular error message included an SSL warning, I would check if you need to explicitly require openssl and/or that your openssl setup is correct. I've had a similar problem with geocoding timing out in my application though the stack trace was a bit different. It took a long time for the Geocoding to complete (because the address was really weird for example) but the rest of my code kept going. I think the stack trace is a bug in Geokit. Since you don't have control over how fast this runs you should consider first of all doing something to reduce the number of times you're making this call, so at a bare minimum:
def full_address
@full_address ||= Geocoder.address("#{self.latlon.x}, #{self.latlon.y}")
end
You should also consider storing full_address as a calculated field since the above code will still run every time that instance of the model is accessed the first time. So getting rid of the code above and instead adding a full_address field and a before save hook:
in a migration file:
add_column :models, :full_address, :string
and in your model.rb:
before_save :geocode_address
def geocode_address
self.full_address = Geocoder.address("#{self.latlon.x}, #{self.latlon.y}") if self.changed.include?("latlon")
end
This way the call only runs when the latlon.x and latlon.y variables are updated, not every time the address is accessed.