Class: Graticule::Geocoder::Mapquest

Inherits:
Base
  • Object
show all
Defined in:
lib/graticule/geocoder/mapquest.rb

Overview

Mapquest uses the Licenced Community API which requires an api key. You can sign up an account and get an api key by registering at: developer.mapquest.com/

mq = Graticule.service(:mapquest).new(API_KEY) location = gg.locate('44 Allen Rd., Lovell, ME 04051')

42.78942, -86.104424

Defined Under Namespace

Classes: Address, Locations, Request, Response, Result

Constant Summary

Constants inherited from Base

Base::USER_AGENT

Instance Method Summary collapse

Constructor Details

#initialize(api_key, open = false, restrict_to_country = nil) ⇒ Mapquest

Returns a new instance of Mapquest.


14
15
16
17
18
19
20
21
22
# File 'lib/graticule/geocoder/mapquest.rb', line 14

def initialize(api_key, open = false, restrict_to_country = nil)
  @api_key = api_key
  @url = if open
           URI.parse('http://open.mapquestapi.com/geocoding/v1/address')
         else
           URI.parse('http://www.mapquestapi.com/geocoding/v1/address')
         end
  @country_filter = restrict_to_country
end

Instance Method Details

#locate(address) ⇒ Object

Locates address returning a Location


25
26
27
# File 'lib/graticule/geocoder/mapquest.rb', line 25

def locate(address)
  get :q => address.is_a?(String) ? address : location_from_params(address).to_s
end