DEV Community

Best practices: Async Reverse Geocoding with Ruby and Geocoder

Victor Hazbun on June 22, 2019

What's up guys? Today I will share with you how I approach reverse geocoding using the Geocoder gem. As you may know the Ruby gem Geocoder lets yo...
Collapse
 
tomk32 profile image
Thomas R. Koll

I'm using GeoCoder as part of Ahoy and its README recommends Geolite2 for a quicker local search which I found totally fine for me purposes. There's even a debian and arch packages for geolite2.

Collapse
 
superails profile image
Yaroslav Shmarov

+1, I also went this way for one project, works well.

here's my geocoder.rb setup

# config/initializers/geocoder.rb
def valid_geo_file
  file_path = "#{Rails.root}/GeoLite2-City.mmdb"
  return file_path if File.exist?(file_path)
end

Geocoder.configure(
  lookup: :mapbox,
  ip_lookup: :geoip2,
  api_key: Rails.application.credentials.dig(:mapbox, :token),
  geoip2: {
    file: valid_geo_file
  }
)
Enter fullscreen mode Exit fullscreen mode