Has anyone done this? I’m confused at how I can make this work, first off I have my user model
Geocoding with it works fine in IRB, just can’t figure out how to get it to work in my project.
Trying to use some examples from the readme here: http://github.com/andre/geokit-rails/tree/master.
Anyhow here is what I have:
class User < ActiveRecord::Base
# geokit
acts_as_mappable
after_save :locate
def locate
location = Geokit::Geocoders::MultiGeocoder.geocode("12.12.12.12")
end
end
This corresponds with my save action in my userController, I need to do this after save because authlogic provides the IP after it saves the user or session. I think eventually I’ll make it a background process, but till then how can I get this to work? I have a location column in the user model that I’ll store the results of geocode()
Also right now I just have some arbitrary IP address “12.12.12.12” but it should actually be current_login_ip
For one of my current projects I accomplished something very similar to what you are trying to do. The big thing to consider is that you do not want to do a new geocoding request every time a model is saved. It is rather time consuming and inefficient to do if you do not need to get new geocoordinates every time.
Also geocoding results obtained from IP addresses are highly inaccurate. Sometimes you will get decent results, but many time you will get coordinates of some data center in another nearby town. If you are looking for regional accuracy, IP geocoding accuracy may be good enough for what you’re trying to do.
This is how I tackled the problem of not rerequesting geocoding if the attributes had not changed: