Rails and geo plugins

After looking into Cartographer and YM4R I started searching for other geo tools for Ruby.

I found several and started creating a list. My idea was to make a comparison between the features of the different plugins. But I soon found out James Stewart did this already in his Comparing rails geo-plugins post. He moved the information to a wiki, on which the most recent information about the different Geo plugins can be found. On this page you’ll also find some great reviews of the different plugins.

I started looking into GeoKit, acts_as_geocodable and actsaslocateable. The last one isn’t suitable for my application, because it can only deal with US addresses. That’s also true for some of the geocoding services the other two support. The only one1 with support for Dutch addresses is the Google geocoding service, so sadly no fall back mechanism for Dutch addresses when one geocoding service isn’t available.

There are a few differences between the remaining two plugins.

acts_as_geocodable makes use of a gem called Graticule. This gem takes care of the actual geocoding, communicating with external services, etc. The acts_as_geocodable plugin takes care of the Rails specific stuff (extra find methods, etc).

GeoKit has all the functionality in the plugin, but Bill Eisenhauer, one of the authors, said “there’s no reason why this needs to be packaged entirely as a plugin”. So maybe this will change one day.

Another important difference is the way the two plugins store the geocoded information. GeoKit can handle existing models with longitude and latitude columns. You can specify the names of the columns with the column_name parameters (the defaults are ‘lat’ and ‘lng’).

The acts_as_geocodable plugin creates two new tables. The first is called geocodes and stores the longitude and latitude for a given address. The second table links the geocodes into your model in a polymorphic way.

Both plugins als have a feature the other plugin doesn’t have (as far as I can tell).

acts_as_geocodable can update the address fields with the data returned from the geocoding service, just add acts_as_geocodable :normalize_address => true to your model.

GeoKit has the ability to look up a location based on the user’s IP-address.

Which of the two is better? I don’t know. They almost have the same feature set, GeoKit does IP-based location lookups, while acts_as_geocodable separates its functionality between the plugin and the gem and has the ability to normalise addresses.

I think it’s a matter of taste, which one to choose. Or is there any difference in performance? I guess I have to test this.

For now, I think I’ll start with GeoKit for my application. I really like the ability to keep my own models with the longitudes and latitudes.

1 Maybe someday I’ll write a post about addresses and zip codes in The Netherlands and why the aren’t available for free.

Leave a Reply