Geokit 1.2: Gem + Rails plugin, Rails 2.2.2 ready
Dec 21, 2008 by
Andre
Geokit gets some love!
- Gem released: Geokit is now separated into a Gem (geokit-gem) and a Rails plugin (geokit-rails). You can use the gem separately. The plugin requires the gem.
- Rails 2.2.2 compatible: the plugin is all updated for Rails 2.2.2
- Many bug fixes/updates:
- Improved Geocoder.us support -- respects authentication, and can geocode city names or zipcodes alone
- cross-meridian finds work correctly with bounds conditions
- fixed a problem with columns with "distance" in their name
- added Geonames geocoder
- the gem and plugin are now hosted at Github. The overall site is still athttp://geokit.rubyforge.org
Geokit makes it easy to build location-based apps. It provides geocoding, location finders, and distance calculation in an easy-to-use API.
Comments
Tom on Dec 24
Hi Andre,
excellent work, thank you! I have one thought though: On a clean ubuntu 8.10 with REE and Passenger (all latest) the gem works nicely but installing the plugin doesn't work out.
After script/plugin install git://github.com/andre/geokit-rails.git the plugin doesn't show up with plugin list. Nor does "require 'geokit-rails/defaults'" work. I keep getting this error when starting console on a brand new rails 2.2.2 app:
tom@rails:/var/www/cabchap$ script/console
Loading development environment (Rails 2.2.2)
/opt/ruby-enterprise-1.8.6-20081215/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- Geokit (MissingSourceFile)
No problems when just the gem is installed. Any ideas? Thanks!
ketan on Dec 26
gem install mysql
Successfully installed mysql-2.7.3-x86-mswin32
1 gem installed
Installing ri documentation for mysql-2.7.3-x86-mswin32...
Installing RDoc documentation for mysql-2.7.3-x86-mswin32...
ERROR: While generating documentation for mysql-2.7.3-x86-mswin32
... MESSAGE: Unhandled special: Special: type=17, text=""
... RDOC args: --op
c:/ruby/lib/ruby/gems/1.8/doc/mysql-2.7.3-x86-mswin32/rdoc --exclude ext
--main README --quiet ext README docs/README.html
(continuing with the rest of the installation)
Andre Lewis on Dec 26
@tom: this was a capitalization problem in init.rb -- it's fixed now if you reinstall the plugin.
@ketan: this looks like a mysql gem problem. Make sure your setup works without geokit before adding geokit to the mix.
Andre
Tom on Dec 27
Thank you Andre! I was really digging deep in the source, but was unable to identify this seemingly simple problem.
Excellent plugin, excellent support.
Sandeep on Jan 05
Hi Andre,
I am able to install the gem ok, cannot seem to install the plugin, please see below console output
C:\PROJECTS\geotest>gem install actionwebservice
Successfully installed actionwebservice-1.2.6
1 gem installed
Installing ri documentation for actionwebservice-1.2.6...
Installing RDoc documentation for actionwebservice-1.2.6...
C:\PROJECTS\geotest>ruby script/plugin install git://github.com/andre/geokit-rails.git
removing: C:/PROJECTS/geotestgeokit/vendor/plugins/geokit-rails/.git
Please let me know why this would happen
Thanks in advance!
Joerg Battermann on Jan 05
Hello there Andre,
Awesome! Quick Q: are there any plans to add reverse geocoding (which google added a while back) to do the lat/lng >> Address conversion?
Cheers,
-Jörg
Andre on Jan 05
@Sandeep -- not sure ... I've heard that git is temperamental on windows, but I don't have a windows box around to try it on. Try installing another github-based plugin, and let me know if you're able to sort it out.
Hey @Joerg, I don't have any plans personally, but it would probably be very straightforward to write. If someone were to branch from github and create it (with tests :-) ) I'd be happy to incorporate it.
Don Park on Jan 08
I have a question and I think it'd be helpful to have some mention of this on http://geokit.rubyforge.org/.
Does GeoKit require or optionally make use of the spatial extensions for SQL such as PostGIS and/or MySQL 5 spatial extensions? It looks like it does not.
If not, what column types does GeoKit expect for lat/long?
And finally, is the project paying attention to http://dev.w3.org/geo/api/spec-source.html ? It got a great list of field names that should be a base for any geo-record SQL table. most notably the distinction between horizontal accuracy and altitude accuracy, which is a useful distinction for GPS devices.
Andre Lewis on Jan 09
@Don - Geokit doesn't require or make use of spatial extensions. Having simple lat/lng columns covers a surprising breadth of use cases, and it's much easier to get up and running. I use decimal(15,10) columns to store lat & lng.
Thanks also for the link.
Cheers,
Andre
Robert Najlis on Jan 25
Thanks for this gem/plugin - its very helpful.
One thing about Google geocoding is that it can't geocode an address with the word 'floor' in it. To get around this, I checked the address, and if it includes the word floor, I use the Yahoo geocoder. I wonder if you would want to include something like this in the MultiGeocoder.
Also I had a problem getting the config setup with just the gem installed (no plugin). I copied the config from the gem website and put it in lib/geokit_config.rb That did not work, so I just installed the plugin and it worked. But I don't actually need the plugin
Thanks.
Robert
Andre Lewis on Jan 26
@Robert: make sure you require 'lib/geokit_config' someplace (environment.rb, or in another initializer). Rails only loads things from lib automatically if the filename is the same as the class name.
I recommend just putting your configuration in a file in the initializers directory -- everything in there gets loaded automatically.
Seth on Jan 28
Thanks for this. Very helpful and a snap to begin using the plugin and acts_as_mappable with the google provider.
So, what are the steps for configuring geonames as a provider? I didn't find any clues in assets/api_keys_template. I tried the obvious config changes, but my log says "Something has gone very wrong during geocoding..."
Seth
Dale on Jan 29
I fear this may be a stupid question, but how does one use the geonames geocoder in the Rails plugin? I don't see an environment.rb config line.
Seth on Jan 30
following up to my own post (and to dale@13) wrt geonames in the plugin.
solved - and my issue had nothing to do with geokit. just my inexperience.
script/plugin update (and script/plugin install as well) pointing to a git url will fail silently if git-core isn't installed. had to go get git-core port for my mac to get the latest plugin via git, and then all's well.
Seth
Bruce on Jan 31
Sweet plugin and gem! Just trying to go through the API to learn about the features... I can't find one that is probably very simple:
How do I create a location object out of a model instance? Say I have @my_store (with lat and lng attributes), and I want to determine and print the full_address (or something similar). How do I do it?
Thanks!
Andre Lewis on Feb 01
@Seth, @Dale: the class is Geokit::Geocoders::GeonamesGeocoder. You can set the username at Geokit::Geocoders::geonames="username"
@Bruce: you're in luck, I just added reverse geocoding (Google only): res=Geokit::Geocoders::GoogleGeocoder.reverse_geocode "37.791821,-122.394679"
Typically, it gives you an address range. Better to start off with an address and geocode it to a lat/lng if possible.
Dale on Feb 04
Thanks, Andre, for the pointer to the geonames geocoder config. With that set AND geonames as the only active geocoder, works as advertised.
Now a complete hack question: I have a local copy of the geonames data (performance-driven). Is it feasible for me to look at hacking GeoKit to work off my own geonames service wrappers against a local db? Just thought I get an opinion before diving in head first :-)
Andre Lewis on Feb 04
@Dale: it will probably be a lot of work. I haven't looked at the geonames data, but I built a geocoder off census data, and it was a serious effort. There's a chapter on it in my book. Bottom line: use one of the services if at all possible.
Dale on Feb 04
Andre, thanks again for the quick reply.
On using services: I've got a commercial app. Google want $10K / year min up front. Nonstarter. Similar for Yahoo. US and CA are not world-wide (needed). Geonames has tested out with the best coverage with acceptable business terms, but at ~2 sec roundtrip, the service can't keep up with a burst need I have for up to 200 geocodes in
I actually have the data model well in brain, along with a collection of wrappers that retrieve what I need. So the question is really more to whether the GeoKit code is structured and packaged such that it's worth the effort to adapt. As productive as your are with updates, I don't want to build an orphan :-)
BTW, your book was the first geo code/mapping purchase 2 years back. It's still on the top of the reference stack. For the audience, it's without peer :-)
Andre Lewis on Feb 04
Dale,
Got it ... structurally, I think it would be straightforward to build the local Geonames geocoder around Geokit. Specifically, I would create a LocalGeonamesGeocoder inheriting from Geokit::Geocoders::BaseGeocoder. All the action goes in your do_geocode method.
For distribution, I'd say ultimately package it up as a separate gem, dependent on Geokit.
Immediate advantages: 1) You get the GeoLoc class for free to hold the results of geocoding calls; 2) You already know the geocoder API so there's nothing to reinvent; 3) you can use one or more of the geocoding services as fallbacks (via the MultiGeocoder) in case you get the occasional failure from your local DB.
If you do it and put it up on github, I think there will be a *lot* of people willing to build on and help maintain the result.
Dale on Feb 06
Ok, I'll start as you suggest. Should the work progress, I'll post an update.
Prashant on Apr 03
Hi Andre,
I am planning to use geokit for my location search project and I wanted an opinion on how the performance would be compared to directly using MYSQL's Spatial search. So specifically for distance-based finders, say I am looking to search for all restaurants within a 10 mile radius, will it do a full table scan? Do you have any benchmarks, which will help us easily use your plugin as compared to the more complex spatial features of the Database?
Dev Singh on May 15
I was using an earlier version of geokit plugin on a rails 2.3 app and just updated to this latest version - the one that now uses a gem.
In the previous version it was possible to convert the object returned by the .geocode method to json. by just call the to_json methon on it.
This however breaks in the new version.
I noticed there is an attribute @all in the new geoLoc which produces a circular reference error if you call to_json on it.
Here is the error:
ActiveSupport::JSON::CircularReferenceError (object references itself)
I am using the "json" to plot markers on the map via jquery. Of course, I can make my own string from the geoLoc result and convert that to json - but it is more code...
Can you tell me why that attribute has been added in the new version and is there another way to directly convert the geoLoc result to json?
Andre
on
May 15
Hey there -- the easiest way right now is to call `my_geoloc.to_hash.to_json`
The circular ref happens because geocoding calls can return multiple results, which are kept in the @all attribute.