Geocoding API's response was not valid JSON. and request.location = nil
Asked Answered
H

2

9
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).

Humph answered 12/12, 2014 at 5:24 Comment(0)
P
1

config/initalizers/geocoder.rb

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

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

Piping answered 2/1, 2015 at 18:50 Comment(0)
B
1

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.

Brooklyn answered 25/11, 2015 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.