Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Nielsen,</p> <p>While it is great for address geocoding using the configured 'lookup' service, unfortunately the <strong>geocoder</strong> gem is hardcoded to use only Freegeoip for all IP address lookups. And I agree with you that Freeogeoip has fairly poor accuracy (not good enough for my use case).</p> <p>From geocoder.rb:</p> <pre><code>def lookup(query) if ip_address?(query) get_lookup(ip_lookups.first) else get_lookup(Configuration.lookup || street_lookups.first) end end ## # All IP address lookups, default first. # def ip_lookups [:freegeoip] end </code></pre> <p>I think that a better solution would be to use the <strong>geoip</strong> gem (<a href="http://geoip.rubyforge.org/" rel="nofollow">http://geoip.rubyforge.org/</a>) with the free MaxMind GeoCityLite database, or if you need even more accuracy you can get the premium version. I am getting significantly more accuracy with GeoCityLite then Freegeoip, even though Freegeoip claims to be derived from the same original database...</p> <p>I am using the following GeoIP call to resolve the location for an IP address:</p> <pre><code>@geoip_city = GeoIP.new('lib/GeoLiteCity.dat').city(request.remote_ip) </code></pre> <p>There are two things to keep in mind: </p> <ol> <li><p>This will only work accurately on live requests, as your local network/loopback adapter will not provide an IP that works for the request.remote_ip call. </p></li> <li><p>The flat file lookup is very fast, but I am still not sure if there is any potential for memory leaks or other scalability problems. I am still testing this solution so I will update response if I find anything significant.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload