Geocoder请求位置在生产中返回nil

我一直在尝试使用geocoder gem获取用户当前位置,但是它在生产中崩溃并每次返回“ nil”。

我尝试使用其他IP,另一台计算机,同样的东西... 我尝试使用.safe_location,但它也为零。

这是我的代码,以防万一:

  @location = request.safe_location

  unless @location.nil?
     @places = Place.near([@location.latitude,@location.longitude])
  end

仅供参考,我也尝试过我们request.location.city。仍然是“零类没有方法”。

我在我编写的10个不同应用程序上使用了Geocoder,但从未遇到过此问题。不过,每次都在Heroku中,第一次在AWS中。

我还使用地理编码器获取Place.near(params [:address]),并且工作正常,因此我可以确认gem的实现是好的。

那可能从哪里来?

非常感谢!

hustsky012 回答:Geocoder请求位置在生产中返回nil

这些方法通常会在测试和开发环境中返回nil,因为localhost0.0.0.0之类的东西不是地理编码的IP地址。

阅读完整的文档here

本文链接:https://www.f2er.com/3164774.html

大家都在问