Home > MQ-Proxy

MQ-Proxy

MQ-Proxy is a project mainly written in Ruby, based on the MIT license.

Ruby wrapper for MapQuest's API

= MQProxy

Connect to Map Quest's API to:

  • geocode address
  • get route from one address to another

== Installation

=== gem gem install mqproxy

=== Plugin

Rails <= 2.3.8 ./script/plugin install git://github.com/cbrady/MQ-Proxy.git

Rails >= 3.0 rails plugin install git://github.com/cbrady/MQ-Proxy.git

== Example

=== Set up the addresses:

Addresses can be setup in a Hash: address1 = {:postalCode => "", :street => "", :adminArea1 => "", :adminArea3 => "", :adminArea4 => "",:adminArea5 => ""} address2 = {:postalCode => "", :street => "", :adminArea1 => "", :adminArea3 => "", :adminArea4 => "",:adminArea5 => ""}

Or as strings: address1 = " , " address2 = " , "

=== To get route: proxy = MQProxy.new route = proxy.get_route(address1, address2)

This returns a MQProxyRoute object

MQProxyRoute gives you access to certain attributes from the MapQuest response: time - total estimated travel time (seconds) distance - total distance of trip (default: miles - can be overwritten in options sent to MapQuest) directions - array of all steps of the trip raw - Hash containing entire response from MapQuest

=== To get geocode:

proxy = MQProxy.new
code = proxy.geocode_address(address1)

This returns a MQProxyGeocode object

MQProxyGeocode gives you access to certain attributes from the MapQuest response: street - address' street city - address' city zip - address' zip code county - address' county state - address' state country - address' country lat - address' latitude lgn - address' longitude raw - Hash containing entire response from MapQuest

== Options: To overwrite default MapQuest options pass mq_options Hash to method

proxy = MQProxy.new
route = MQProxy.get_route(address1, address2, :mq_proxy => {:unit => 'k', :routeType => 'shortest'})

The this tells MapQuest that you would like the shortest route possible and all of the distances in the response to be in kilometers instead of miles.

For a full list of options see the MapQuest API documentation:

http://www.mapquestapi.com/

Copyright (c) 2011 Christopher Brady, released under the MIT license