简体   繁体   English

Geokit和rails 3

[英]Geokit and rails 3

I am using the geokit gem and plugin with rails 3. It seems there is a known issue with them, which can be seen here http://github.com/andre/geokit-rails/issues#issue/15 我正在使用带有rails 3的geokit gem和插件。看起来有一个已知的问题,可以在这里看到http://github.com/andre/geokit-rails/issues#issue/15

Now, I tried to follow the solution provided at the bottom. 现在,我尝试按照底部提供的解决方案。 I pasted that function definition, at the end of the file, just above acts_as_mapable, and just after the first time it was called, but nothing happened each time. 我将该函数定义粘贴在文件末尾,就在acts_as_mapable之上,并且在第一次调用它之后,但每次都没有发生任何事情。

Any idea what else can be done? 知道还能做些什么吗?

Thanks 谢谢

I ran into similar problems upgrading my app to rails 3. I'm still using Geokit for geocoding but Active Record scopes for distance based database queries. 我遇到类似的问题将我的应用程序升级到rails 3.我仍然使用Geokit进行地理编码,但Active Record范围用于基于距离的数据库查询。 It's pretty convenient, and you still get all of the Active Record 3 goodness. 它非常方便,你仍然可以获得所有Active Record 3的优点。 Here's 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's a blog post with a little more detail on the subject: http://stcorbett.com/code/distance-queries-with-rails-3-without-geokit/ 这是一篇关于这个主题的更多细节的博客文章: http//stcorbett.com/code/distance-queries-with-rails-3-without-geokit/

jlecour's port to rails 3 should solve any issues you were having last year. jlecour的rails 3的端口应解决你去年遇到的任何问题。

Make sure you're using mysql or postgres if you're doing distance calculations. 如果你正在进行距离计算,请确保使用mysql或postgres。

After trouble installing the geokit-rails3 gem on Rails 3.1 I moved to the geocoder gem . 在Rails 3.1上安装geokit-rails3 gem之后出现问题,我移动到了地理编码器gem It has distance calculation as well (be sure to not forget the s in @your_model.nearby* s *(5)). 它也有距离计算(一定不要忘记@ your_model.nearby * s *(5)中的s )。 There is also a Railscast . 还有一个Railscast

Here is port of geokit to rails 3, incomplete through: 这是geokit到rails 3的端口,不完整通过:

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

对于仍然遇到geokit问题的人,我继续使用mongodb ...它有内置距离搜索n ...

Hey Amit, Not sure if you sorted this out yet but I'll tell you what I did just in case. 嘿阿米特,不确定你是否已将其整理出来,但我会告诉你我做了什么以防万一。

I forked andre's geokit-rails source and then cloned it locally and added the code from this gist at line 34 of lib/geokit-rails/acts-as-mappable.rb , just after the line that reads module ClassMethods # :nodoc: . 我分叉了andre的geokit-rails源,然后在本地克隆它,并在lib/geokit-rails/acts-as-mappable.rb34行添加了这个要点的代码,就在读取module ClassMethods # :nodoc:

Then I commited those changes back to my forked repo on github and used my fork to install the source as a plugin to my rails 3 app. 然后我将这些更改提交回github上的forked repo并使用我的fork将源代码作为插件安装到我的rails 3 app。 That seemed to work straight away, but make sure you have the acts_as_mappable line added to whatever model you are wanting to do distance calculations on and make sure you have two float columns on that db named :lat and :lng . 这似乎可以直接使用,但请确保将acts_as_mappable行添加到您想要进行距离计算的任何模型中,并确保在该db上有两个名为:lat:lng 浮点列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM