Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails geocoder rails gem中的request.location对heroku来说是否太慢?_Ruby On Rails_Heroku_Rails Geocoder - Fatal编程技术网

Ruby on rails geocoder rails gem中的request.location对heroku来说是否太慢?

Ruby on rails geocoder rails gem中的request.location对heroku来说是否太慢?,ruby-on-rails,heroku,rails-geocoder,Ruby On Rails,Heroku,Rails Geocoder,在过去的一周里,我注意到在我使用Geocoder gem来请求.location的页面上,我的heroku应用程序经常显示出来 Application Error An error occurred in the application and your page could not be served. Please try again in a few moments. If you are the application owner, check your logs for detai

在过去的一周里,我注意到在我使用Geocoder gem来请求.location的页面上,我的heroku应用程序经常显示出来

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.  
If you are the application owner, check your logs for details.  
日志显示

Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...)  
我以前从未注意到这个问题,但也许它一直存在,只是直到最近我才经常访问有这个问题的页面。与访问页面相比,超时的发生似乎是随机的

所以我补充说

Geocoder.configure(
  :timeout => 40
)
到我的config/initializers/geocoder.rb。我认为这会导致访问页面的次数增加,但加载页面通常需要一段时间

我在这些页面上实现了一个默认的邮政编码,这样就不会出现应用程序错误,但从长远来看,这并不理想

我试过了

if params[:search].present?
   @events = Event.near(params[:search], params[:dist], order: 'distance') 
elsif user_signed_in? && current_user.address
  @events = Event.near([current_user.latitude, current_user.longitude], 25, order: 'distance') 
elsif request.location 
  @events = Event.near([request.location.latitude, request.location.longitude], 25, order: 'distance') 
else
  @events = Event.near(20016, 100, order: 'distance')
当request.location超时时,我希望得到一个默认zipcode为20016,但我仍然得到应用程序错误


还有其他建议吗?

如果您为Geocoder gem设置了超时,则需要将其设置为小于30秒,这是您向Heroku发出的每个请求的时间长度。当超时设置为40秒时,对IP地理定位服务的地理编码器请求将在40秒后超时——但是在Heroku已经超时的时候,您会看到H12应用程序错误。将超时设置为小于30秒,您至少应该看到默认的邮政编码


Geocoder
request.location
方法将尝试使用默认IP地理编码服务FreeGeoIP对请求IP地址进行地理编码。最近(2015年11月),他们似乎遇到了一些问题。您可以尝试其他IP服务(如Telize),看看这是否也有助于解决问题

谢谢你的回答,卢卡斯!在某个时候,我将超时设置为30,但仍然存在问题。我将超时设置为20,并将位置替换为“华盛顿特区”。我认为20016可能不是位置的有效值。至少现在它在使用request.location和“华盛顿特区”之间摇摆不定。是的,我应该更清楚一些。如果地理编码器超时设置为30,您仍然会看到H12超时,因为请求的总时间将超过30秒。