Sha256: d2a893b846ec5936c96a291f786b63c39502d975060e5f1af2be26304a59bb4c

Contents?: true

Size: 1.35 KB

Versions: 25

Compression:

Stored size: 1.35 KB

Contents

require 'geocoder/lookups/base'
require "geocoder/results/nominatim"

module Geocoder::Lookup
  class Nominatim < Base

    def name
      "Nominatim"
    end

    def map_link_url(coordinates)
      "http://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
    end

    def query_url(query)
      method = query.reverse_geocode? ? "reverse" : "search"
      host = configuration[:host] || "nominatim.openstreetmap.org"
      "#{protocol}://#{host}/#{method}?" + url_query_string(query)
    end

    private # ---------------------------------------------------------------

    def results(query)
      return [] unless doc = fetch_data(query)
      doc.is_a?(Array) ? doc : [doc]
    end

    def parse_raw_data(raw_data)
      if raw_data.include?("Bandwidth limit exceeded")
        raise_error(Geocoder::OverQueryLimitError) || Geocoder.log(:warn, "Over API query limit.")
      else
        super(raw_data)
      end
    end

    def query_url_params(query)
      params = {
        :format => "json",
        :addressdetails => "1",
        :"accept-language" => (query.language || configuration.language)
      }.merge(super)
      if query.reverse_geocode?
        lat,lon = query.coordinates
        params[:lat] = lat
        params[:lon] = lon
      else
        params[:q] = query.sanitized_text
      end
      params
    end
  end
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
geocoder-1.4.5 lib/geocoder/lookups/nominatim.rb
geocoder-1.4.4 lib/geocoder/lookups/nominatim.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/geocoder-1.4.3/lib/geocoder/lookups/nominatim.rb
geocoder-1.4.3 lib/geocoder/lookups/nominatim.rb
geocoder-1.4.2 lib/geocoder/lookups/nominatim.rb
geocoder-1.4.1 lib/geocoder/lookups/nominatim.rb
geocoder-1.4.0 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.7 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.6 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.5 lib/geocoder/lookups/nominatim.rb
broken-geocoder-1.3.6 lib/geocoder/lookups/nominatim.rb
broken-geocoder-1.3.5 lib/geocoder/lookups/nominatim.rb
broken-geocoder-1.3.4 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.4 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.3 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.2 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.1 lib/geocoder/lookups/nominatim.rb
geocoder-1.3.0 lib/geocoder/lookups/nominatim.rb
geocoder-1.2.14 lib/geocoder/lookups/nominatim.rb
geocoder-1.2.13 lib/geocoder/lookups/nominatim.rb