GeoKit: A Tiny Update

Its been a while since I tinkered with GeoKit, but when I read this post, I thought I’d take a look at a couple of things that were mentioned.

James wrote that it would be nice to be able to reset the default_units value to enable localization.  Well, actually you can.  :default_units is modifiable through a class accessor.  Also, you can pass an optional parameter in your finders called :units which enables you to override whatever default value you’ve set.

While we’re talking about defaults, I applied a patch submitted by Hoan Ton-That which enables you to specify your preferences for units and for the formula from within the environment files.  So these preferences would appear right along side your API keys for GeoKit.  Its a small feature, but you may appreciate it.  Thanks Hoan!

Otherwise, James mentioned that :include support is lacking with GeoKit.  That’s not entirely true.  I added a passing test case which successfully pulls columns from a belongs_to relationship.  I suspect that the has_many relationships are the problem.  But if your case is covered by the belongs_to relationship, then you are covered.

There is a less-used method called distance_sql which enables you to just get the distance calculation in SQL form.  You would use this if you ever found that GeoKit could not support your exact query requirements.  Its less elegant for sure, but saves you the trouble of having to code the distance calculation.

UK geocoding is still in the roadmap, but both Andre and I have a few other projects and side endeavors going on.

This entry was posted in GeoKit, Open Source, Ruby, Ruby on Rails. Bookmark the permalink.

4 Responses to GeoKit: A Tiny Update

  1. Dan Kubb says:

    Bill, in the post you referenced there’s a comment about making the following possible:


    stops = BusStop.find(:all, :o rigin => ‘1319 Fulton St. East, Grand Rapids MI 49503′, :o rder => ‘distance’)
    distance_in_km = stops.first.distance(:km)
    distance_in_miles = stops.first.distance(:miles)

    What do you think about this?

  2. Well, the request is basically to add a distance converter. As I suggested in a comment that James hasn’t yet approved, its easy enough to write yourself a helper for this which does the conversion for you.

    Its trivial enough for us to implement, so maybe we should just do it. Maybe we should just extend Number to have a to_miles and a to_kms where it just takes the base value and applies the appropriate formula.

  3. Xin says:

    Bill, I would love it if GeoKit supported UK Geocoding.

    Have you any thoughts how they might be implemented? Since only Google AJAX Search API supports detailed UK geocoding.

  4. dudzjosh says:

    It seems this include problem is known already with rails.

    http://dev.rubyonrails.org/ticket/5371

    I’m currently trying to think of a work around…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>