GeoX is the latest kid on the Ruby on Rails geocoding block. The plugin was announced a couple of weeks ago and I’ve been meaning to explore it ever since, just in case it had any new features and also so that I can add it to my comparison chart.
The feature set of GeoX is fairly straightforward. It supports a number of geocoding back ends: obviously google and yahoo are covered, but also mapquest’s relatively recent API. The standard lookup process is much like that provided by several other plugins—the sample given is:
require 'geox'
# uses the google engine
geocoder = GeoX::Geocoder.new(:geoengine => GeoX::Google)
location = {:address => '701 Ocean St', :post_code => '95060'}
geocode = geocoder.geocode(location)
# geocode will be a hash containing the geocode data returned from the server
puts geocode.inspect
What is most notably lacking is any ActiveRecord integration such as that offered by acts_as_locateable or acts_as_geocodable. That is apparently by design as the intention is for the library to be usable outside rails but the plugin relies on the rails-specific blank? method and personally I prefer the graticule/acts_as_geocodable split where functionality equivalent to that of GeoX is bundled in the graticule gem and then ActiveRecord hooks are provided by the plugin. It is definitely nice to have geocoding handled manually when models are added or updated, but more than that it is very useful to have support provided for searching based on location.
Probably the most intriguing aspect of the plugin is the facility to compare the specificity of two different sets of coordinates. That’s achieved by returning an object type appropriate to the specificity. So if you have street-level data, the object returned is an instance of GeoX::Street. Operator overloading allow you to compare the objects:
puts "Street wins!" if GeoX::Street.new < GeoX::Block.new
The README file suggests putting the API keys in the file lib/geox_api_keys.rb within the plugin. That’s probably not the best of ideas, but it would be easy enough to rework it so that the configuration is done in the usual rails way and the plugin can be included with svn:externals or piston.
I can’t see myself switching to GeoX from the options I currently use and it’s a shame that its distinctive features weren’t submitted as patches to existing projects rather than adding yet another plugin to the increasingly crowded scene, but it’ll be interesting to see how it evolves over the coming months.