Sha256: cfc25f2e7da1a7d5ecc17e83b86c1c594bf4a07e424cfe7f84879aa647de5fd4

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 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 query_url_params(query)
      params = {
        :format => "json",
        :polygon => "1",
        :addressdetails => "1",
        :"accept-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

4 entries across 4 versions & 2 rubygems

Version Path
geocoder-1.1.8 lib/geocoder/lookups/nominatim.rb
geocoder-1.1.7 lib/geocoder/lookups/nominatim.rb
geocoder-sgonyea-1.1.6.1 lib/geocoder/lookups/nominatim.rb
geocoder-1.1.6 lib/geocoder/lookups/nominatim.rb