Igor Alexandrov

Programming and something else…

ipgeobase.ru Support in Geocoder Gem

| Comments

For some reason geocoder gem don’t have support of ipgeobase.ru out of the box.

You may don’t know this, but ipgeobase.ru is leading ip-geocoding service in Russia and Ukraine. Its accuracy of coordinates detection for Russian ip-addresses is much higher then in the freegeoip.net. For example, I live in Tver and my home ip-address is; freegeoip tells me that I am in Moscow, ipgeobase tells me that I am in Tver, about 150 kilometres difference!

That’s why I decided to add support of ipgeobase to geocoder.

With some ideas brought from Kirill Mokevnin’s ipgeobase gem, I added a couple of classes to geocoder. Here is a usage example:

1.9.3-p327 :001 > Geocoder.configure(:ip_lookup => :ipgeobase)
 => {:timeout=>3, :lookup=>:google, :ip_lookup=>:ipgeobase, :language=>:en, :http_headers=>{}, :use_https=>false, :http_proxy=>nil, :https_proxy=>nil, :api_key=>nil, :cache=>nil, :cache_prefix=>"geocoder:", :always_raise=>[], :units=>:mi, :distances=>:linear}
1.9.3-p327 :002 > Geocoder.search("").first
 => #<Geocoder::Result::Ipgeobase:0x007fb373986fb0 @data={"inetnum"=>" -", "country"=>"RU", "city"=>"Тверь", "region"=>"Тверская область", "district"=>"Центральный федеральный округ", "lat"=>"56.857929", "lng"=>"35.923828", "ip"=>""}, @cache_hit=nil>
1.9.3-p327 :003 > Geocoder.coordinates("")
 => [56.857929, 35.923828]

All changes are packed into a pull-request on GitHub. Vote for it if you want to see ipgeobase.ru support in the latest release of geocoder.