Geocoding with Ruby on Rails

Posted by Jeremy Voorhis Wed, 01 Feb 2006 21:09:00 GMT

I have spent a little bit of time these days at PLANET ARGON dealing with geocoding. You know, Google maps, proximity search, the works.

Last Sunday, Bryan Wood just posted his geocoding library for Ruby on Rails, including a MySQL dump with coordinates for every US zipcode and a Location model that knows trigonometry

I wanted to play with this, but as those of you in the audience who have been following along already know, we at PLANET ARGON are just as opinionated as the next guys. More specifically, we are biased towards PostgreSQL for our database needs. To combat cognitive dissonance, I fired up sed and a throw-away Ruby script and created this migration. I haven’t tested it with MySQL yet, but it ought to work with anything that supports migrations.

Comments

  1. topfunky said about 2 hours later:

    I’ll put this to use immediately!

    Thanks!

  2. tarek said 5 days later:

    have you messed with PostGIS at all?

  3. tarek said 5 days later:

    have you messed with PostGIS at all?

  4. tarek said 5 days later:

    have you guys messed with PostGIS at all?

  5. tarek said 11 days later:

    so, err, sorry about the triple post above… one note on postgres: if you add a UNIQUE constraint on the zipcode, it will index the zip, which will make for faster queries than the string comparison which it’s doing now.

    my post migration:

    class AddUniqueConstraintOnZipcodes < ActiveRecord::Migration def self.up execute %q{ALTER TABLE locations ADD CONSTRAINT locations_zipcode_unique UNIQUE ;} end end

    def self.down
      execute %q{ALTER TABLE locations DROP CONSTRAINT locations_zipcode_unique;}
    end

(leave url/email »)