Skip to content

Commit

Permalink
Add support for Nominatim
Browse files Browse the repository at this point in the history
This adds support for Nominatim-based reverse geocoding, along with
Photon and Geofi. To use it, set the environment variables:

NOMINATIM_API_HOST - the host name of the OSM Nominatim server
NOMINATIM_API_USE_HTTPS - use the HTTPS to connect
NOMINATIM_API_KEY - the API key
  • Loading branch information
Cyberax committed Jan 9, 2025
1 parent 0625a4f commit 8e61445
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/initializers/01_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
PHOTON_API_KEY = ENV.fetch('PHOTON_API_KEY', nil)
PHOTON_API_USE_HTTPS = ENV.fetch('PHOTON_API_USE_HTTPS', 'true') == 'true'

NOMINATIM_API_HOST = ENV.fetch('NOMINATIM_API_HOST', nil)
NOMINATIM_API_KEY = ENV.fetch('NOMINATIM_API_KEY', nil)
NOMINATIM_API_USE_HTTPS = ENV.fetch('NOMINATIM_API_USE_HTTPS', 'true') == 'true'

GEOAPIFY_API_KEY = ENV.fetch('GEOAPIFY_API_KEY', nil)
# /Reverse geocoding settings
6 changes: 5 additions & 1 deletion config/initializers/03_dawarich_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class DawarichSettings
class << self
def reverse_geocoding_enabled?
@reverse_geocoding_enabled ||= photon_enabled? || geoapify_enabled?
@reverse_geocoding_enabled ||= photon_enabled? || geoapify_enabled? || nominatim_enabled?
end

def photon_enabled?
Expand All @@ -17,5 +17,9 @@ def photon_uses_komoot_io?
def geoapify_enabled?
@geoapify_enabled ||= GEOAPIFY_API_KEY.present?
end

def nominatim_enabled?
@nominatim_enabled ||= NOMINATIM_API_HOST.present?
end
end
end
6 changes: 6 additions & 0 deletions config/initializers/geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
elsif GEOAPIFY_API_KEY.present?
settings[:lookup] = :geoapify
settings[:api_key] = GEOAPIFY_API_KEY
elsif NOMINATIM_API_HOST.present?
settings[:lookup] = :nominatim
settings[:nominatim] = { use_https: NOMINATIM_API_USE_HTTPS, host: NOMINATIM_API_HOST }
if NOMINATIM_API_KEY.present?
settings[:api_key] = NOMINATIM_API_KEY
end
end

Geocoder.configure(settings)

0 comments on commit 8e61445

Please sign in to comment.