Geokit and rails 3

I use the geokit gem and the plug-in with rails 3. There seems to be a known problem with them, which can be seen here http://github.com/andre/geokit-rails/issues#issue/15

Now I tried to execute the solution presented below. I put this function definition at the end of the file just above act_as_mapable and right after its first call, but nothing happened every time.

Any idea what else can be done?

thanks

+4
source share
6 answers

For those who are still experiencing geokit problems, I switched to using mongodb ... which has a built-in search for distance n of everything ...

+1
source

I had similar problems updating my application to rails 3. I still use Geokit for geocoding, but Active Record areas for database-based queries based on distance. This is pretty convenient, and you still get all of Active Active 3. Here is an example from my User model:

scope :near, lambda{ |*args| origin = *args.first[:origin] if (origin).is_a?(Array) origin_lat, origin_lng = origin else origin_lat, origin_lng = origin.lat, origin.lng end origin_lat, origin_lng = deg2rad(origin_lat), deg2rad(origin_lng) within = *args.first[:within] { :conditions => %( (ACOS(COS(#{origin_lat})*COS(#{origin_lng})*COS(RADIANS(users.lat))*COS(RADIANS(users.lng))+ COS(#{origin_lat})*SIN(#{origin_lng})*COS(RADIANS(users.lat))*SIN(RADIANS(users.lng))+ SIN(#{origin_lat})*SIN(RADIANS(users.lat)))*3963) <= #{within} ), :select => %( users.*, (ACOS(COS(#{origin_lat})*COS(#{origin_lng})*COS(RADIANS(users.lat))*COS(RADIANS(users.lng))+ COS(#{origin_lat})*SIN(#{origin_lng})*COS(RADIANS(users.lat))*SIN(RADIANS(users.lng))+ SIN(#{origin_lat})*SIN(RADIANS(users.lat)))*3963) AS distance ) } } 

Here is a blog post with a bit more detailed information on the topic: http://stcorbett.com/code/distance-queries-with-rails-3-without-geokit/

+7
source

jlecour port to rails 3 should solve any problems that occurred last year.

Make sure you use mysql or postgres if you are doing distance calculations.

+4
source

After the geokit-rails3 gem installation error on Rails 3.1, I moved to the geocoding gem . It also has a distance calculation (be sure to remember s in @ your_model.nearby * s * (5)). There is also a Railscast .

+3
source

Here is the geokit port for rails 3, incomplete through:

https://github.com/jlecour/geokit-rails3

+1
source

Hey Amit, Not sure if you made it out, but I will tell you what I did just in case.

I searched for the source of andre geokit-rails, and then cloned it locally and added this meaning code in line 34 of lib/geokit-rails/acts-as-mappable.rb , right after the line that reads module ClassMethods # :nodoc:

Then I made these changes back to my forked repo on github and used my plug-in to install the source as a plugin in my rails 3 app. It seemed to work right away, but make sure the acts_as_mappable line acts_as_mappable added to any model on which you want to do distance calculations, and make sure you have two float columns on this db named :lat and :lng .

0
source

All Articles