Class: Graticule::Geocoder::MapQuest

Inherits:
Rest
  • Object
show all
Defined in:
lib/graticule/geocoder/map_quest.rb

Overview

First you need a Mapquest API key. You can register for one here: www.mapquest.com/features/main.adp?page=developer_tools_oapi

Then you create a MapquestGeocode object and start locating addresses:

gg = Graticule.service(:map_quest).new(MAPS_API_KEY)
location = gg.locate :street => '1600 Amphitheater Pkwy', :locality => 'Mountain View', :region => 'CA'
p location.coordinates

Constant Summary collapse

PRECISION =
{
  0 => Precision.unknown,
  'COUNTRY' => Precision.country,
  'STATE' => Precision.state,
  'COUNTY' => Precision.state,
  'CITY' => Precision.city,
  'ZIP' => Precision.zip,
  'ZIP7' => Precision.zip,
  'ZIP9' => Precision.zip,
  'INTERSECTIONS' => Precision.street,
  'STREET' => Precision.street,
  'ADDRESS' => Precision.address
}

Constants inherited from Base

Base::USER_AGENT

Instance Attribute Summary

Attributes inherited from Base

#preference

Instance Method Summary collapse

Methods inherited from Base

#<=>

Constructor Details

#initialize(key) ⇒ MapQuest

Creates a new MapquestGeocode that will use Mapquest API key key.

WARNING: The MapQuest API Keys tend to be already URI encoded. If this is the case be sure to URI.unescape the key in the call to new



34
35
36
37
# File 'lib/graticule/geocoder/map_quest.rb', line 34

def initialize(key)
  @key = key
  @url = URI.parse 'http://web.openapi.mapquest.com/oapi/transaction'
end

Instance Method Details

#locate(address) ⇒ Object

Locates address returning a Location



40
41
42
# File 'lib/graticule/geocoder/map_quest.rb', line 40

def locate(address)
  get map_attributes(location_from_params(address))
end