土工套件和导轨 3

发布于 2024-09-14 15:02:13 字数 333 浏览 6 评论 0 原文

我正在使用 ruby​​-on-rails 3 的 geokit gem 和插件。它们似乎存在一个已知问题,可以在此处看到 http://github.com/andre/geokit-rails/issues#issue/15

现在,我尝试遵循底部提供的解决方案。我将该函数定义粘贴到文件末尾,就在 actions_as_mapable 上方,并且就在第一次调用它之后,但每次都没有发生。

知道还能做什么吗?

谢谢

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

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.

Any idea what else can be done?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

十级心震 2024-09-21 15:02:13

我在将应用程序升级到 Rails 3 时遇到了类似的问题。我仍在使用 Geokit 进行地理编码,但使用 Active Record 范围进行基于距离的数据库查询。这非常方便,而且您仍然可以获得 Active Record 3 的所有优点。这是我的用户模型的一个示例:

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
                    )
                  }
                }

这是一篇博客文章,其中包含有关该主题的更多详细信息:

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. It's pretty convenient, and you still get all of the Active Record 3 goodness. 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/

疑心病 2024-09-21 15:02:13

jlecour 的 Rails 3 移植 应该可以解决您去年遇到的任何问题。

如果您正在进行距离计算,请确保您使用的是 mysql 或 postgres。

jlecour's port to rails 3 should solve any issues you were having last year.

Make sure you're using mysql or postgres if you're doing distance calculations.

ヅ她的身影、若隐若现 2024-09-21 15:02:13

在 Rails 3.1 上安装 geokit-rails3 gem 遇到问题后,我转向了 geocoder gem。它还具有距离计算功能(请务必不要忘记 @your_model.nearby*s*(5) 中的 s)。还有一个 Railscast

After trouble installing the geokit-rails3 gem on Rails 3.1 I moved to the geocoder gem. It has distance calculation as well (be sure to not forget the s in @your_model.nearby*s*(5)). There is also a Railscast.

云裳 2024-09-21 15:02:13

这是 geokit 到 Rails 3 的端口,不完整:

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

Here is port of geokit to rails 3, incomplete through:

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

无人问我粥可暖 2024-09-21 15:02:13

对于那些仍然遇到 geokit 问题的人,我继续使用 mongodb...它内置了距离搜索功能...

For those still having trouble with geokit, i moved on to using mongodb... which has inbuilt distance search n all...

多彩岁月 2024-09-21 15:02:13

嘿阿米特,不确定你是否已经解决了这个问题,但我会告诉你我做了什么,以防万一。

我分叉了 andre 的 geokit-rails 源代码,然后将其克隆到本地,并在 this gist 中的代码lib/geokit-rails/acts-as-mappable.rb 的 >34,就在 module ClassMethods # :nodoc: 行之后。

然后我将这些更改提交回 github 上的分叉存储库,并使用我的分叉将源代码作为插件安装到我的 Rails 3 应用程序中。这似乎可以立即生效,但请确保将 acts_as_mappable 行添加到您想要进行距离计算的任何模型中,并确保有两个 float 列该数据库名为 :lat:lng

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:.

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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文