Class: MapQuest::Services::Geocoding

Inherits:
Core
  • Object
show all
Defined in:
lib/mapquest/services/geocoding.rb

Overview

The main class used for communicating with the MapQuest Geocoding API

Defined Under Namespace

Classes: Response, TooManyLocations

Constant Summary collapse

API_LOCATION =
:geocoding
VALID_OPTIONS =
[:location,:maxResults,:thumbMaps]

Instance Attribute Summary

Attributes inherited from Core

#mapquest

Instance Method Summary collapse

Methods inherited from Core

#call_api, #initialize

Constructor Details

This class inherits a constructor from MapQuest::Services::Core

Instance Method Details

#address(location, options = {}) ⇒ Object

Allows you to search for a single location and returns a response object of the found locations

Example: .address :location => "London, UK"

Required parameters

  • location [String] The location for which you wish to get data

Optional parameters

  • :maxResults [Integer] The number of results to limit the response to. Defaults to -1 (-1 indicates no limit)

  • :thumbMaps [Boolean] Return a URL to a static map thumbnail image for a location. Defaults to true

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/mapquest/services/geocoding.rb', line 20

def address(location, options = {})
  raise ArgumentError, 'Method must receive a location (string)' unless location
  options[:location] = location
  call_api self, 1, 'address', options
end

#reverse(location, options = {}) ⇒ Object

Allows you to search for a location using lat/lng values and returns a response object of the found locations

Example: .reverse :location => ['40.0755','-76.329999']

Required parameters

  • location [Array] The lat, and lng to search for

Optional parameters

  • :maxResults [Integer] The number of results to limit the response to. Defaults to -1 (-1 indicates no limit)

  • :thumbMaps [Boolean] Return a URL to a static map thumbnail image for a location. Defaults to true

Raises:

  • (ArgumentError)


35
36
37
38
39
# File 'lib/mapquest/services/geocoding.rb', line 35

def reverse(location, options = {})
  raise ArgumentError, 'Method must receive a location (array)' unless location && location.kind_of?(Array)
  options[:location] = location.join(',')
  call_api self, 1, 'reverse', options
end