alexreisner / geocoder

Complete Ruby geocoding solution.
http://www.rubygeocoder.com
MIT License
6.35k stars 1.2k forks source link

Config w/ multiple API providers for forward lookup results in Nominatin lookup #1352

Closed posiczko closed 5 years ago

posiczko commented 6 years ago

Multiple API providers were defined in the initializer per README:

Geocoder.configure(
  timeout:      3,
  cache:        Redis.new,
  cache_prefix: "geocoder",

  location_iq:  {
      api_key: Rails.application.credentials[:geocoding][:location_iq_key]
  },

  opencagedata: {
      api_key: Rails.application.credentials[:geocoding][:opencage_data_key]
  },

  mapbox:       {
      api_key: Rails.application.credentials[:geocoding][:mapbox_token]
  }
)

Expected behavior

For non-cached lookups, expected result is the for the first available API which does not time out/error out to provide result.

Actual behavior

Result was provided by Nominatin:

[1] pry(main)> results = Geocoder.search ("1600 Pennsylvania Ave NW, Washington, DC")
=> [#<Geocoder::Result::Nominatim:0x00007fc942d7baf0
  @cache_hit=false,
  @data=
   {"place_id"=>"238019587",
    "licence"=>"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
    "osm_type"=>"way",
    "osm_id"=>"238241022",
    "boundingbox"=>["38.8974898", "38.897911", "-77.0368542", "-77.0362526"],
    "lat"=>"38.8976998",
    "lon"=>"-77.0365534886228",
    "display_name"=>"White House, 1600, Pennsylvania Avenue Northwest, Golden Triangle, Washington, District of Columbia, 20500, USA",
    "class"=>"historic",
    "type"=>"building",
    "importance"=>1.0276757387296138,
 ...

Adding lookup: :mapbox to the configure does result in lookup by Mapbox.

Maybe I'm misunderstanding something? Should configuration with multiple sources result in first available API to respond? Many thanks for your work!

Environment info

alexreisner commented 5 years ago

Your expectation is reasonable, but not how the gem actually works. There are no fallback lookups, it just uses the one you configure (using :lookup), with Nominatim as the default. There's been talk about using fallbacks (see #351) but it's quite complicated.