Giter VIP home page Giter VIP logo

google-directions-ruby's Introduction

Usage

directions = GoogleDirections.new(origin, destination)

where origin and destination are strings of addresses or places that Google 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 Google returns with every turn, or the API call URL


xml = directions.xml
xml_call = directions.xml_call

Error situations

status: NOT_FOUND

If Google can’t recognize your places, the distance_in_miles and drive_time_in_minutes will each return 0. You can call

directions.status
and it should return “NOT_FOUND” (directions.status will also return any other Google API call statuses)

status: OVER_QUERY_LIMIT

If Google thinks you’ve hit their API too many times in day, or too rapidly, for your given IP address and API key; they might return OVER_QUERY_LIMIT. In this case distance_in_miles and drive_time_in_minutes will each return 0. You can call

directions.status
and it should return “OVER_QUERY_LIMIT”

Installation

gem

rails 3.0/4.0

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

Compatibility

Tested on Rails 2.3.8
Tested on Rails 4.0.1

Google maps API key

You’ll need a Google Map API key

http://code.google.com/apis/maps/signup.html

Include it as the constant GOOGLE_MAPS_API_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

GoogleDirections.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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.