Sha256: b948ae01fb3665415fcac4ed16c02656029906abdd0573404bd8f89b3d2eafe5

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

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

module Geocoder::Lookup
  class Yandex < Base

    def map_link_url(coordinates)
      "http://maps.yandex.ru/?ll=#{coordinates.reverse.join(',')}"
    end

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

    def results(query, reverse = false)
      return [] unless doc = fetch_data(query, reverse)
      if err = doc['error']
        warn "Yandex Geocoding API error: #{err['status']} (#{err['message']})."
        return []
      end
      if doc = doc['response']['GeoObjectCollection']
        meta = doc['metaDataProperty']['GeocoderResponseMetaData']
        return meta['found'].to_i > 0 ? doc['featureMember'] : []
      else
        warn "Yandex Geocoding API error: unexpected response format."
        return []
      end
    end

    def query_url(query, reverse = false)
      query = query.split(",").reverse.join(",") if reverse
      params = {
        :geocode => query,
        :format => "json",
        :plng => "#{Geocoder::Configuration.language}", # supports ru, uk, be
        :key => Geocoder::Configuration.api_key
      }
      "http://geocode-maps.yandex.ru/1.x/?" + hash_to_query(params)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
geocoder-1.1.3 lib/geocoder/lookups/yandex.rb
geocoder-1.1.2 lib/geocoder/lookups/yandex.rb
geocoder-1.1.1 lib/geocoder/lookups/yandex.rb
geocoder-1.1.0 lib/geocoder/lookups/yandex.rb
geocoder-1.0.5 lib/geocoder/lookups/yandex.rb
geocoder-1.0.4 lib/geocoder/lookups/yandex.rb
geocoder-1.0.3 lib/geocoder/lookups/yandex.rb
geocoder-1.0.2 lib/geocoder/lookups/yandex.rb
geocoder-1.0.1 lib/geocoder/lookups/yandex.rb
geocoder-1.0.0 lib/geocoder/lookups/yandex.rb