Ruby-wrapper for MapQuest Directions API. Can return the drive time and driving distance between two places.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit ahead of joshcrews:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
README.textile
Rakefile
init.rb

README.textile

Usage

Get a MapQuest API key, and store in your app under MAPQUEST_KEY

MAPQUEST_KEY = ‘your_api_key’

directions = MapQuestDirections.new(origin, destination)

where origin and destination are strings of addresses or places that MapQuest can find an address for. Example: “816 Meridian St., 37207”

Get drive time or distance of whole trip


drive_time_in_minutes = directions.drive_time_in_minutes
distance_in_miles = directions.distance_in_miles

Get the XML MapQuest returns with every turn, or the API call URL


xml = directions.xml
xml_call = directions.xml_call

Error situations

directions.status
shows you the status code returned by MapQuest. 0 means worked. Other codes (500, 403) mean problem.

If MapQuest can’t recognize your places or gives an error, the distance_in_miles and drive_time_in_minutes will each return 0. You can call

directions.status
and it should tell you a number code for the problem. You can call
directions.xml
to read the full text.

Installation

gem

rails 2.3

  1. gem install mapquest_directions
  2. add config.gem “mapquest_directions” to your environment.rb file

rails 3.0

  1. gem ‘mapquest_directions’ in your Gemfile
  2. bundle install
    from command line

Rails plugin

Rails 2.3

script/plugin install git://github.com/joshcrews/mapquest-directions-ruby.git

Rails 3.0

rails plugin install git://github.com/joshcrews/mapquest-directions-ruby.git

Compatibility

Tested on Rails 2.3.8

Not yet tested on Rails 3. It probably is Rails 3 compatible, because it’s just a single class with a few methods. It’s probably compatible with every ruby project ever.

MapQuest maps API key

You’ll need a MapQuest Map API key

http://developer.mapquest.com/

Include it as the constant MAPQUEST_KEY in an app configuration file (environment.rb, config/initializers/api_keys.rb)

Need turn-by-turn directions?

Not yet included in this gem, but you can do it with nokogiri to parse the XML that comes back when you do

MapQuestDirections.new(origin, destination).xml

And then nokogiri can cycle through each and you can pick out what you need.

License

Anyone can use this code in any way.