所以我正在使用Geocoder https://github.com/alexreisner/geocoder根据用户提交表单时提供的地址提取纬度和经度坐标。我这样做是为了使用 Google 地图 API 绘制标记。这在开发中非常有效——零问题。然而,当我投入生产时,地理编码器不会生成纬度和经度。我检查了我的生产日志,错误为零。我还检查以确保 gem 不仅仅是为了开发而安装的,并且我已经在我的生产机器上重新启动了 unicorn 和 nginx。关于可能发生的事情有什么想法吗?
这是我正在执行此任务的模型的模型代码--
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
============更新============
因此,经过建议后,我使用以下命令打开了生产机器上的 Rails 控制台:
bundle exec rails console production
然后跑了——
Geocoder.search("San Francisco, CA")
产生了这个错误——
Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...) to set limit).
=> []
话虽这么说,在我的 config/initilizers/geocoder.rb 文件中,我有——
Geocoder::Configuration.timeout = 15
设置什么合适的超时限制?我需要坐标,但也不想让它永远运行......
===========更新=============
我找到了这个相关问题 https://stackoverflow.com/questions/6451099/using-geocoder-on-production-server,尽管我更喜欢在服务器端运行此任务,而不是在客户端。