Geocoder Gem 在生产环境中不起作用 [英] Geocoder Gem not working in Production Environment

查看:74
本文介绍了Geocoder Gem 在生产环境中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 Geocoder 根据用户提交表单时.我这样做是为了可以使用 Google Maps API 绘制标记.这在开发中非常有效 - 零问题.但是,当我投入生产时,地理编码器不会生成纬度和经度.我检查了我的生产日志,错误为零.我还进行了检查以确保 gem 不仅是为了开发而安装的,而且我已经在生产机器上重新启动了 unicorn 和 nginx.关于会发生什么的任何想法?

So I am using Geocoder to pull in latitude and longitude coordinates based on an address provided by a user when submitting a form. I am doing this so that I can plot markers using the Google Maps API. This works perfectly in development - zero issues. When I push to production however, the latitude and longitude are not generated by Geocoder. I have checked my production logs and there are zero errors. I also checked to make sure that the gem is not just installed for development and I have restarted unicorn and nginx on my production machine. Any ideas as to what could be going on?

这是我正在执行此任务的模型的模型代码 --

Here is my model code for the model I am preforming this task in --

class Order < ActiveRecord::Base

  attr_accessible :city, :customer_email, :customer_id, :delivery_date, :delivery_time, :street, :zipcode, :coupon, :total, :name, :items_with_day, :user_id, :shopping_cart_id, :extras, :latitude, :longitude, :location_name, :phone, :suite, :state

  belongs_to :user

  validates :name, :presence => true
  validates :street, :presence => true
  validates :city, :presence => true
  validates :zipcode, :presence => true

  def address
    [street, city, state, "United States"].compact.join(', ')
  end

  geocoded_by :address
  after_validation :geocode

end

============ 更新 ==============

所以在建议之后,我使用 --

So after a suggestion, I opened up the rails console on my production machine using --

bundle exec rails console production

然后跑--

Geocoder.search("San Francisco, CA")

产生此错误的原因 --

which generated this error --

Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...) to set limit).
=> []

话虽如此,在我的 config/initilizers/geocoder.rb 文件中,我有 --

that being said, in my config/initilizers/geocoder.rb file, I have --

Geocoder::Configuration.timeout = 15

要设置的适当超时限制是多少?我需要坐标,但也不想让它永远运行......

What is an appropriate timeout limit to set? I need the coordinates, but also don't want to let this run forever...

============ 更新 ==============

=========== UPDATE =============

我发现了这个相关问题,但我更愿意运行这个任务服务器侧,而不是在客户端.

I found this related question, though I would prefer to run this task server side, instead of on the client side.

推荐答案

Geocoder gem 的作者有 这个要说:

The author of the Geocoder gem has this to say:

[A]您确定应用服务器在您添加 Geocoder 后重新启动了吗?

[A]re you sure the app server was restarted since you added Geocoder?

首先,通过在您的生产控制台中发出 Geocoder 命令来验证 gem 确实已安装:

First, verify that the gem is indeed installed by issuing a Geocoder command in your production console:

# from the production console
Geocoder.search("San Francisco, CA")

如果这没有抛出任何错误,尝试重新启动服务器.软启动可能有效——硬启动更好.这将重新加载整个 Rails 环境,包括所有已安装的依赖项.

If this does not throw any errors, try restarting the server. A soft boot might work – a hard boot is better. This will reload your entire Rails environment, inclusive of any installed dependencies.

更新:

正如对此答案的评论中所述,问题与Geocoding API 响应速度不够快 错误有关.

As mentioned in the comments to this answer, the problem is related to the Geocoding API not responding fast enough error.

合适的超时时间是多久?

这很难说.gem 的作者 建议 15,因为你已经有了它调成.地理编码服务可能会暂时变慢 - 或者总体上可能变慢.IMO,将其逐渐调高并找到它开始工作的数字 - 然后将其留在那里.

That's hard to say. The gem's author suggests 15, as you already have it set to. The geocoding service may be momentarily slow – or it may be slow overall. IMO, set it incrementally higher and find the number where it starts working – then leave it there.

请注意,客户端与服务器端参数可能不适用这里.OP 问题中引用的 SO 帖子与请求配额有关.相比之下,问题中出现的问题似乎与地理编码速度有关,无论是客户端还是服务器调用都不会影响地理编码速度.

Note that the client-side vs. server-side argument may not apply here. The SO post cited in the OP's question relates to request quotas. The problem being witnessed in the question, in contrast, seems to relate to geocoding speed, which would not be affected whether the calls are made by the client or by the server.

这篇关于Geocoder Gem 在生产环境中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆