Question

I have an Event model that when an address is entered in a form and submitted it geocodes the address to latitude and longitude and saves these values in the event's record.

In order to combat people not entering the city and state of Austin and Texas I added a method in my event model and changed it to geocoded_by :full address

def full_address
  addr = self.address
  addr += ' Austin ' unless addr.include?('Austin')
  addr += ' Texas ' unless addr.include?('Texas')
  addr
end

This works fine for new events being submitted. However, I have a number of events that need to be tested by this and their latitude and longitude updated in the database accordingly.

Looking for information on how this is done.

Was it helpful?

Solution

Given that you have existing records with an address that is wrong and that there has been no geocoding for that entry you can run:

rake geocode:all CLASS=YourModel

See: http://rubydoc.info/gems/rails-geocoder/0.9.10/file/README.rdoc

If the entries without "Austin Texas" is already geocoded (but not correct) you could either search for all addresses not containing austing/texas and have them re-geocoded.

Or if there's not that many entries, you could simply reset all of the stored lat/long positions and the run the rake geocode:all command again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top