ActsAsLocateable released 16

Posted by Jeff Sat, 30 Dec 2006 01:54:00 GMT

Introducing my 2nd adventure into Rails plugins: ActsAsLocateable!

ActsAsLocateable is an easy way to give any model the ability to be found by location. For instance, say you have a model Store which is associated with a zip code indicating where that Store is located. To find all the stores within a specific radius of another ZipCode, you can do a

Store.find_within_radius(10, 12345)     # Find all stores within 10 miles of zip code 12345

Install ActsAsLocateable in the normal way

script/plugin install http://svn.baconbear.com/rails_plugins/acts_as_locateable/trunk/

Be sure to read the associated README file after the install for details on installation, setup, and usage.

ActsAsLocateable is based heavily on the ZipCodeSearch plugin by Doug Fales and utilizes much of the same code and data. Special thanks to Doug for making his code freely available!

Comments

Leave a response

  1. Joshua Warchol Thu, 04 Jan 2007 22:15:13 GMT
    Neat plugin. Couple of questions. Why are latitude and longitude stored in the DB as strings as opposed to floats? I redid the migration with floats and it seems to work well. I also added an index to speed things up. add_index :zip_codes, [:latitude, :longitude] And to help folks using MySQL, here's the faster load syntax: LOAD DATA INFILE '[your filename]' INTO TABLE zip_codes FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (zip, latitude, longitude, city, state, zip_class);
  2. Jeff Lee Fri, 05 Jan 2007 01:32:17 GMT
    Good suggestions. I originally didn't make those changes simply because that's the way ZipCodeSearch did things. I'll make the changes and post an update when I get a chance.
  3. James Stewart Wed, 07 Feb 2007 21:06:39 GMT
    It would be nice to be able to pass in standard AR conditions and have them applied to the query too. That way I could, say, search for all events within a given radius and on a certain day. I've patched my copy and can email a diff if you'd like. Pasting it in here seems to lose all the formatting.
  4. James Stewart Wed, 07 Feb 2007 21:17:45 GMT
    I've actually posted the patch over on my blog. You can find it at: http://jystewart.net/process/archives/2007/02/extending-acts_as_locateable/
  5. casino di internet Tue, 04 Dec 2007 11:38:14 GMT
    Qui vi insegniamo a giocare ai migliori giochi del casinò di internet per meglio vincere un sacco di soldi.
  6. punenet.com Sun, 16 Dec 2007 09:29:43 GMT
    Auf punenet.com können Sie alle Spielregeln für das Spielen im Online Casino nachlesen!
  7. Casino Wed, 26 Dec 2007 01:52:33 GMT
    Das Casinoland entführt Sie in die Welt der Online Casinos und zeigt Ihnen, wo Sie sicher spielen können.
  8. backgammon games Tue, 08 Jan 2008 09:07:55 GMT
    Backgammon online is easy to play and enjoyable, check out our backgammon guide to find out how and where to play.
  9. casinos Fri, 25 Jan 2008 13:12:32 GMT
    Hey, thanks for sharing this information. I see that I am not the only one with problems in this field.
  10. Matt Sun, 03 Aug 2008 17:26:46 GMT
    Thanks!!! I made a few tweaks to work w/ my app... # Change data type to float t.column :latitude, :float t.column :longitude, :float # Modify lat/lon floats and index execute("ALTER TABLE zip_codes MODIFY latitude float(10,7);") execute("ALTER TABLE zip_codes MODIFY longitude float(10,7);") add_index :zip_codes, [:latitude, :longitude], :name = 'latlon' # Removed the + symbol in the .csv file Search: ","+ Replace: "," # Added James Stewart's patch (Thanks James!)
  11. Spielbank Tue, 16 Sep 2008 06:41:07 GMT
    Very nice. Spielbanken Deutschland appreciates the tipps.
  12. Spielbank Tue, 16 Sep 2008 06:41:22 GMT
    Very nice. Spielbanken Deutschland appreciates the tipps.
  13. Jesse Mon, 05 Jan 2009 16:45:19 GMT
    James, I totally agree with you!
  14. Jesse Mon, 05 Jan 2009 16:45:41 GMT
    James, I totally agree with you!
  15. Frustrated Fri, 20 Feb 2009 03:12:05 GMT
    I'm trying this with Rails 2.1.0 and it's not working for me. I followed the README's example:

    class Item < ActiveRecord::Base
       has_one :zip_code
       acts_as_locateable :through => :zip_code
    end

    My User has a ZipCode, but the acts_as_locateable.rb seems not to be working properly as far as calling the Instance Methods for lat and lon (latitude and longitude) are concerned. I've tried fixing this, but whenever I run this:

    User.find_within_radius(10, 77006)

    ....SQLite3 always complains that User does not have a longitude! It's supposed to be figuring out that User is locateable through ZipCode and asking the associated ZipCode for a longitude. :(
  16. mmorpg Sat, 07 Mar 2009 19:47:47 GMT
    interesting read
Comments