Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geocoding API's response was not valid 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 am getting request.location nil. i tried to add timeout in configuration but it not helped for me.

error in production mode as "Geocoding API's response was not valid JSON."

and when i traced it i got request.location as nil.

my geocoder version is (1.2.6).

like image 462
Shefalee Chaudhary Avatar asked Dec 12 '14 05:12

Shefalee Chaudhary


2 Answers

config/initalizers/geocoder.rb

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

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

like image 161
neonmate Avatar answered Nov 15 '22 08:11

neonmate


It seems that you just have no available action points to access to selected geo services. For me it was too small amount of available requests to Google geo services. I just increated it by registering on Google application serivces, and putting into config Google API key. For services, which determine Geo position by IP, it was recommended :telize since it does not have any request quotas currently by previous answerer. I also advice you to see into side of local IP storage to resovle them to Geo position, like :geoip2, and :maxmind_local. So your geoconfig will be like follows:

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 :telize service currently isn't properly working, returning: Geocoding API's response was not valid JSON.

Please refer to all options to configure goe services on geocoder's README.

like image 29
Малъ Скрылевъ Avatar answered Nov 15 '22 10:11

Малъ Скрылевъ