The geocoding API response is invalid JSON. and 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 

I get request.location nil . I tried to add a timeout in the configuration, but that didn't help me.

production mode error as "Geocoding API response is invalid JSON."

and when I traced it, I received request.location as zero.

my version of the geocoder (1.2.6).

+5
source share
2 answers

It seems that you simply do not have available action points for accessing the selected geographic information services. For me, this was too few available requests for Google geoinformation. I only increased it by registering on Google services and including the Google API key in it. For services that determine the Geo IP position, it was recommended :telize , as it currently does not have request quotas from the previous answering machine. I also advise you to look towards the local IP storage to move them to the Geo position, for example :geoip2 and :maxmind_local . So, your geoconfiguration will look like this:

config /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'] }, } 

NOTE. It seems that the :telize service is currently not working properly, returning: Geocoding API response was not valid JSON .

Refer to all goa service settings on geocoder README .

+1
source

configurations /initalizers/geocoder.rb

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

Source: https://github.com/alexreisner/geocoder/issues/777

0
source

Source: https://habr.com/ru/post/1208860/


All Articles