【问题标题】:Geocoding API's response was not valid JSON. and request.location = nil地理编码 API 的响应不是有效的 JSON。和 request.location = nil
【发布时间】:2014-12-12 05:24:53
【问题描述】:
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。我尝试在配置中添加超时,但对我没有帮助。

生产模式中的错误 “Geocoding API 的响应不是有效的 JSON。”

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

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

【问题讨论】:

    标签: ruby-on-rails ruby geocode


    【解决方案1】:

    config/initializers/geocoder.rb

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

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

    【讨论】:

      【解决方案2】:

      您似乎没有可用的操作点来访问选定的地理服务。对我来说,Google 地理服务的可用请求数量太少。我只是通过在Google 应用程序服务上注册并放入配置 Google API 密钥来创建它。对于由IP 确定Geo 位置的服务,建议使用:telize,因为它目前没有前一个回答者的任何请求配额。我还建议您查看本地 IP 存储的一侧,以将它们重新定位到地理位置,例如 :geoip2:maxmind_local。所以你的地理配置将如下所示:

      config/initializers/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

      请参考geocoder's README上配置goe服务的所有选项。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多