Rails geocoding gem issues

I am using the geocoder gem and I need to encode the start and end address of the model, however I am not sure if I can accomplish this with this gem, and if I can, if I am doing it correctly. If this cannot be done with a gem, is there another resource that will allow me to geocode two locations in the same form? This is an example of what I am trying to do, but it just passes the second address for geocoding.

geocoded_by :start_address
before_validation :geocode
geocoded_by :delivery_address, :latitude => :end_latitude, :longitude => :end_longitude
before_validation :geocode

      

0


source to share


2 answers


If you look at the source, it looks as if there is a hash parameters to be overwritten active_record.rb and base.rb .



I believe there are two options: move your addresses to the included (merged) model (for example, Address

or whatever)) or fork geocoder to have multiple options by key. The first one is simpler and solves the problem. The second is colder (he can play with it himself as a kata).

+1


source


So what happens is just a ruby ​​... if you do this:

class Question
  def ask
    "what would you like?"
  end

  def ask
    "oh hai"
  end
end

Question.new.ask
 => "oh hai"

      

The last method definition wins ... so when you declare two methods geocoded_by

, the 2nd is considered.



I think you will have to manually geocode using gem

before_validation :custom_geocoding

def custom_geocoding
  start_result = Geocoder.search(start_address)
  end_result = Geocoder.search(delivery_address)
  # manually assign lat/lng for each result
end

      

+1


source







All Articles