GeoKit: Improvements to distance_between and distance_to

Over at Earthcode, a request was made to enable the distance_between and distance_to methods to accept physical locations in pre-geocoded string form. I have added this improvement, so you can now do:

1
2
3
4
5
6
7
# Geocode from and to, then calculate the distance
# between them.
dist = Store.distance_between("Irving, TX", 
                              "San Francisco, CA")

# Geocode the to, then calculate the distance to it.
dist = irving.distance_to("San Francisco, CA")

Andre has also added further flexibility to the :o rigin to include setting it to an array of lat / lng values. Usage looks like:

1
2
3
# Presumably some previous geocoding and then this:
stores = Store.find(:all,  :o rigin => [37.792,-122.393], 
                    :conditions => 'distance < 10') 

Keep the feedback coming!

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

3 Responses to GeoKit: Improvements to distance_between and distance_to

  1. Bernie Wolford says:

    Are these changes in the .zip download at https://rubyforge.org/projects/geokit/ ?

    Could you clarify for a newbie where I should save the geokit files in my ruby directory — I presume at something like c:\ruby\lib\ruby\gems\1.8\gems ?

    Thanks for any guidance that would help me be able to play with geokit as Andre does at http://earthcode.com/blog/2007/02/database_distance_calculations.html

    Regards,
    Bernie

  2. Sure. Its a plugin, so you need to follow the standard plugin script protocol. This varies slightly depending upon whether you run under Windows or Mac OSX.

    Try this:

    ruby script/plugin install svn://rubyforge.org/var/svn/geokit/trunk

  3. Pingback: Web 2.0 Technologies

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>