地理编码API的响应无效JSON。 和request.location = nil

if Rails.env.development? @current_location_geo = Geocoder.search(request.remote_ip).first else @current_location_geo = request.location end if !@current_location_geo.nil? && @current_location_geo.ip == "127.0.0.1" @departure_currency_code= "AUD" @departure_currency_name= ["Australian Dollar(AUD $)","AUD"] else @country = Country.new(request.location.data["country_code"].to_s) @country_code = @country.currency.code end end 

我收到了request.location nil 。 我试图在配置中添加超时但对我没有帮助。

生产模式中的错误为“地理编码API的响应无效JSON”。

当我追踪它时,我得到request.location为零。

我的地理编码器版本是(1.2.6)。

您似乎没有可用的操作点来访问选定的地理位置服务。 对我来说, Google地理服务的可用请求太少了。 我只是通过在Google应用程序服务器上注册并添加配置Google API密钥来增加它。 对于通过IP确定Geo服务,建议:telize因为之前的:telize没有任何请求配额。 我还建议你看看本地IP存储的一面,将它们转移到Geo位置,如:geoip2:maxmind_local 。 所以你的geoconfig将如下:

配置/ initalizers / geocoder.rb:

 Geocoder.configure( lookup: :google, ip_lookup: :geoip2, maxmind_local: { package: :city }, geoip2: { file: File.join('vendor/share', 'GeoLite2-City.mmdb') }, google: { timeout: 20, use_https: true, api_key: ENV['GOOGLE_API_KEY'] }, } 

注意:似乎:telize服务当前没有正常工作,返回: Geocoding API's response was not valid JSON

请参阅所有选项以在地理编码器的README上配置goe服务。

配置/ initalizers / geocoder.rb

 Geocoder.configure( timeout: 10, ip_lookup: :telize ) 

资料来源: https : //github.com/alexreisner/geocoder/issues/777