Sha256: 9b1aeaa07a8e7c021ba75734afb29330cace95e38b066c4012d3820b1066d55a

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

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

module Geocoder::Lookup
  class Google < Base

    def map_link_url(coordinates)
      "http://maps.google.com/maps?q=#{coordinates.join(',')}"
    end

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

    def results(query, reverse = false)
      return [] unless doc = fetch_data(query, reverse)
      case doc['status']; when "OK" # OK status implies >0 results
        return doc['results']
      when "OVER_QUERY_LIMIT"
        warn "Google Geocoding API error: over query limit."
      when "REQUEST_DENIED"
        warn "Google Geocoding API error: request denied."
      when "INVALID_REQUEST"
        warn "Google Geocoding API error: invalid request."
      end
      return []
    end

    def query_url(query, reverse = false)
      params = {
        (reverse ? :latlng : :address) => query,
        :sensor => "false",
        :language => Geocoder::Configuration.language,
        :key => Geocoder::Configuration.api_key
      }
      "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + hash_to_query(params)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geocoder-1.0.5 lib/geocoder/lookups/google.rb
geocoder-1.0.4 lib/geocoder/lookups/google.rb
geocoder-1.0.3 lib/geocoder/lookups/google.rb