geokit无法适用计算机怎么弄,使用Rails 3和Geokit-rails3位置gem(Using Rails 3 with Geokit-rails3 location gem)...

使用Rails 3和Geokit-rails3位置gem(Using Rails 3 with Geokit-rails3 location gem)

我正在尝试使用geokit-rails3 gem来获取rails应用程序中的地理位置信息。 我有一个简单的模型:

class Location < ActiveRecord::Base

def lookup_ip_information(post_ip)

ip = post_ip

location = IpGeocoder.geocode(ip)

puts location.full_address

lat = location.lat

lng = location.lng

end

end

当我用我的控制器中的request.remote_ip调用此方法时,它会抛出一个错误: uninitialized constant Location::IpGeocoder

I am trying to use the geokit-rails3 gem for geolocation information in a rails application. I have a simple model:

class Location < ActiveRecord::Base

def lookup_ip_information(post_ip)

ip = post_ip

location = IpGeocoder.geocode(ip)

puts location.full_address

lat = location.lat

lng = location.lng

end

end

When I call this method with request.remote_ip from my controller, it's throwing an error: uninitialized constant Location::IpGeocoder

原文:https://stackoverflow.com/questions/5244039

更新时间:2020-10-05 13:10

最满意答案

我刚刚遇到了这个问题,并通过输入完整解决了它

Geokit::Geocoders::IpGeocoder.geocode(request.remote_ip)

这似乎为我解决了。

I just had this issue and resolved it by entering the full

Geokit::Geocoders::IpGeocoder.geocode(request.remote_ip)

and that seemed to solve it for me.

相关问答

正确地说,旧版本的haml-rails gem取决于railsite gem 3.2.14 , haml-rails gem的版本,放置在指定的文件夹中取决于railites gem 4.0.1 。 所以你要么: 删除Gemfile并将所有Rails升级到4.x版本。 在大多数情况下,此解决方案将花费很多时间来修复,并且是不合适的。 将放置在路径上的haml-rails gem的HEAD设置为属于版本3.2.13的标记或提交 ,创建一个新分支,并在本地处理gem: cd /path/to/gem/

...

正在运行,正如1 gem installed线所示。 你得到的错误信息是因为Rails文档不会生成 - 许多宝石与他们的自动记录功能有类似的问题。 这不会损害宝石的功能,而且无论如何你都可以去api.rubyonrails.org获取文档。 如果Rails安装实际上失败了,你会看到一些东西(可能会有所不同 - 下面的示例来自本地扩展,可能会有所不同): ERROR: Error installing rails:

[stacktrace]

Gem files will remain inst

...

不要使用sudo 。 只需gem install rails Do not use sudo. Just gem install rails

我碰到类似的问题,将我的应用程序升级到rails 3.我仍然使用Geokit进行地理编码,但Active Record范围用于基于距离的数据库查询。 这非常方便,你仍然可以获得Active Record 3的所有优点。 以下是我的用户模型的示例: scope :near, lambda{ |*args|

origin = *args.first[:origin]

if (origin).is_a?(Array)

...

好的 - 这里是任何需要帮助的人的解决方案。 确保您的项目Gemfile不包含任何类型的任何geokit信息。 安装geokit > gem install geokit

> gem list geo

*** LOCAL GEMS ***

geokit (1.6.0, 1.5.0)

卸载geokit-rails3和geokit-rails31 > gem uninstall geokit-rails31 geokit-rails3

在您的项目中,在根级别: > rails plugin in

...

您应该通过ctrl + c重新启动rails应用程序,或者您应该再次退出rails控制台和rails控制台。 例如 Location.class

NameError: undefined local variable or method `acts_as_mappable' for Location (call 'Location.connection' to establish a connection):Class

from /Users/caiqinghua/.rvm/gems/ru

...

从轨道4开始,我能够从OSX / Ubuntu完全清除轨道的唯一方法是卸载轨道,这将删除轨道和任何相关的轨道rubygem。 如果你想删除一个特定的版本(在你的情况下是4.2.0),你可以执行以下操作: gem uninstall railties -v 4.2.0

The only way I've been able to completely purge rails from OSX/Ubuntu as of rails 4 is to uninstall railties, which

...

它是railties宝石的一部分。 它运行的文件是$YOUR_GEM_INSTALL_PATH/railties-$VERSION/lib/rails/commands/console.rb It is part of the railties gem. The file it runs is $YOUR_GEM_INSTALL_PATH/railties-$VERSION/lib/rails/commands/console.rb

我的解决方案现在有效,可能不是最好的解决方案,只是找不到任何其他方法: address = [lat, long]

users.each do |u|

if u.distance_to(address, :units => :kms) < u.distance

tutors << t

end

end

它是如何工作的 :用户表有一个名为distance的字段,我保留一个整数,显示用户覆盖的半径,例如:20。在进行搜索时,我从表单中发送lat和long pa

...

我刚刚遇到了这个问题,并通过输入完整解决了它 Geokit::Geocoders::IpGeocoder.geocode(request.remote_ip)

这似乎为我解决了。 I just had this issue and resolved it by entering the full Geokit::Geocoders::IpGeocoder.geocode(request.remote_ip)

and that seemed to solve it for me.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值