class Geocoder::Lookup::BanDataGouvFr
def any_result?(doc)
def any_result?(doc) doc['features'] and doc['features'].any? end
def autocomplete_param_is_valid?(param)
def autocomplete_param_is_valid?(param) [0,1].include?(param.to_i) end
def base_query_url(query)
def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" "#{protocol}://api-adresse.data.gouv.fr/#{method}/?" end
def code_param_is_valid?(param)
def code_param_is_valid?(param) (1..99999).include?(param.to_i) end
def latitude_is_valid?(param)
def latitude_is_valid?(param) param.to_f <= 90 && param.to_f >= -90 end
def limit_param_is_valid?(param)
def limit_param_is_valid?(param) param.to_i.positive? end
def longitude_is_valid?(param)
def longitude_is_valid?(param) param.to_f <= 180 && param.to_f >= -180 end
def map_link_url(coordinates)
def map_link_url(coordinates) "https://www.openstreetmap.org/#map=19/#{coordinates.join('/')}" end
def name
def name "Base Adresse Nationale Française" end
def query_ban_datagouv_fr_params(query)
def query_ban_datagouv_fr_params(query) query.reverse_geocode? ? reverse_geocode_ban_fr_params(query) : search_geocode_ban_fr_params(query) end
def query_url_params(query)
def query_url_params(query) query_ban_datagouv_fr_params(query).merge(super) end
def results(query)
def results(query) if doc = fetch_data(query) and any_result?(doc) [doc] else [] end end
def reverse_geocode_ban_fr_params(query)
(check results for a list of accepted types)
:type => force returned results type
:lon => required
:lat => required
### REVERSE GEOCODING PARAMS ####
def reverse_geocode_ban_fr_params(query) lat_lon = query.coordinates params = { lat: lat_lon.first, lon: lat_lon.last } unless (type = query.options[:type]).nil? || !type_param_is_valid?(type) params[:type] = type.downcase end params end
def search_geocode_ban_fr_params(query)
For up to date doc (in french only) : https://adresse.data.gouv.fr/api/
:citycode => force filter results on a specific city UUID INSEE code
:postcode => force filter results on a specific city post code
(check results for a list of accepted types)
:type => force filter the returned result type
:lon => force filter results around specific lat/lon
:lat => force filter results around specific lat/lon
(default = 1)
:autocomplete => pass 0 to disable autocomplete treatment of :q
in account in geocoder
(default = 5) note : only first result is taken
:limit => force limit number of results returned by raw API
def search_geocode_ban_fr_params(query) params = { q: query.sanitized_text } unless (limit = query.options[:limit]).nil? || !limit_param_is_valid?(limit) params[:limit] = limit.to_i end unless (autocomplete = query.options[:autocomplete]).nil? || !autocomplete_param_is_valid?(autocomplete) params[:autocomplete] = autocomplete.to_s end unless (type = query.options[:type]).nil? || !type_param_is_valid?(type) params[:type] = type.downcase end unless (postcode = query.options[:postcode]).nil? || !code_param_is_valid?(postcode) params[:postcode] = postcode.to_s end unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode) params[:citycode] = citycode.to_s end unless (lat = query.options[:lat]).nil? || !latitude_is_valid?(lat) params[:lat] = lat end unless (lon = query.options[:lon]).nil? || !longitude_is_valid?(lon) params[:lon] = lon end params end
def type_param_is_valid?(param)
def type_param_is_valid?(param) %w(housenumber street locality municipality).include?(param.downcase) end