class GooglePlaces::Prediction

Attributes

description[RW]
matched_substrings[RW]
place_id[RW]
structured_formatting[RW]
terms[RW]
types[RW]

Public Class Methods

list_by_input(input, api_key, options = {}) click to toggle source

Query for Predictions (optionally at the provided location)

@option [String,Integer] :lat the latitude for the search @option [String,Integer] :lng the longitude for the search @option options [Integer] :radius (1000)

Defines the distance (in meters) within which to return Place results.
The maximum allowed radius is 50,000 meters.
Note that radius must not be included if :rankby => 'distance' (described below) is specified.

@option options [String,Array] :types

Restricts the results to Spots matching at least one of the specified types

@option options [String] :language

The language code, indicating in which language the results should be returned, if possible.

@option options [Hash] :retry_options ({})

A Hash containing parameters for search retries

@option options [Object] :retry_options ([]) @option options [Integer] :retry_options (0) the maximum retries @option options [Integer] :retry_options (5) the delay between each retry in seconds

# File lib/google_places/prediction.rb, line 39
def self.list_by_input(input, api_key, options = {})
  lat = options.delete(:lat)
  lng = options.delete(:lng)
  language = options.delete(:language)
  radius = options.delete(:radius)
  retry_options = options.delete(:retry_options) || {}
  types  = options.delete(:types)
  components = options.delete(:components)

  options = {
    :input => input,
    :key => api_key,
    :retry_options => retry_options
  }

  if lat && lng
    options[:location] = Location.new(lat, lng).format
    options[:radius] = radius if radius
  end

  # Accept Types as a string or array
  if types
    types = (types.is_a?(Array) ? types.join('|') : types)
    options[:types] = types
  end

  if language
    options[:language] = language
  end

  if components
    options[:components] = components
  end

  request(:predictions_by_input, options)
end
new(json_result_object) click to toggle source
# File lib/google_places/prediction.rb, line 13
def initialize(json_result_object)
  @description = json_result_object['description']
  @place_id = json_result_object['place_id']
  @terms = json_result_object['terms']
  @types = json_result_object['types']
  @matched_substrings = json_result_object['matched_substrings']
  @structured_formatting = json_result_object['structured_formatting']
end
request(method, options) click to toggle source
# File lib/google_places/prediction.rb, line 76
def self.request(method, options)
  response = Request.send(method, options)

  response['predictions'].map do |result|
    self.new(result)
  end
end