GeoKit: More Syntactic Sugar

We just checked in code which improves the readability of GeoKit’s finders. Its quite obvious from the code, so just take a look at these examples:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Find the nearest store.
stores = Store.find(:nearest,  :o rigin => an_origin)

# Find the farthest store away.
stores = Store.find(:farthest,  :o rigin => an_origin)

# Find within a radius.
stores = Store.find(:all, :within => 5,  :o rigin => an_origin)

# Find outside a radius.
stores = Store.find(:all, :beyond => 5,  :o rigin => an_origin)

# Find within a range.
stores = Store.find(:all, :range => 5..10,  :o rigin => an_origin)
This entry was posted in GeoKit, Open Source, Ruby, Ruby on Rails, Uncategorized. Bookmark the permalink.

6 Responses to GeoKit: More Syntactic Sugar

  1. Jeroen Zwartepoorte says:

    Are there any plans to add support for using Google Maps in the view to display results from using geokit? If not, can you recommend a good plugin that fits well with geokit?

  2. Check out this blog (though it is in German):

    http://blog.ebenessen.de/2007/2/17/geokoordinaten-und-google-maps

    where he’s using the YM4R plugin. He uses GeoKit and YM4R in a brief, but useful tutorial.

  3. Jeroen Zwartepoorte says:

    Thanks, while not totally ideal (the plugins store their API keys in 2 different locations), it works ok.

  4. Yeah, well we aren’t affiliated with the YM4R folks and well-behaved plugins usually namespace all their stuff so that they can co-exist peacefully.

    If you don’t like the duplication of keys, consider creating your own variable to keep the key and assign it to the various plugins that need it. With this approach, you can preserve your DRY goals.

    Otherwise, if that’s the extent of your inconvenience, then you are doing pretty well. The value of each plugin easily outweighs your concerns (IMHO).

  5. Sascha Brink says:

    @Jeroen: You’re right. I’ve altered the tutorial a bit. Now GeoKit uses the YM4R-Key.

    Just add to config/environment.rb:
    GeoKit::Geocoders::GOOGLE= Ym4r::GmPlugin::ApiKey::GMAPS_API_KEY

  6. yves says:

    I have been using the plugin wo any problem until today : I needed to use the :range option and I discover that the find :range doesn’t handle the exclusive option at all , I tried several cases :
    p_exclusive = Proposition.find_by_range((0…2), .. and got 89
    p_exclusive = Proposition.find_by_range(Range.new(0,2,true).. got 89

    p_inclusive = Proposition.find_by_range((0..2), .. and got 89
    p_inclusive = Proposition.find_by_range(Range.new(0,2,false).. got 89
    p_inclusive = Proposition.find_by_range(Range.new(0,2).. got 89

    I know my result should be 86, I can exclude the 2.. but the generated SQL is always

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>