This library brings the Google Maps API Web Services to your Ruby/RoR application.
The Ruby Client for Google Maps Services is a Ruby Client library for the following Google Maps APIs:
- Directions API
- Distance Matrix API
- Elevation API
- Geocoding API
- Time Zone API
- Roads API
- Places API
- Static Maps API
- Street View Image API
- Geolocation API
It supports both JSON and XML response formats.
- Ruby 2.1 or later.
- A Google Maps API key.
- Client ID and Client Secret (for Google Maps APIs Premium Plan customers).
Add this line to your application's Gemfile:
gem 'googlemaps-services'
And then execute:
$ bundle
Or install it yourself as:
$ gem install googlemaps-services
View the reference documentation.
This example uses the Directions API with an API key:
require 'googlemaps/services/client'
require 'googlemaps/services/directions'
include GoogleMaps::Services
client = GoogleClient.new(key: 'Add API key here', response_format: :json)
directions = Directions.new(client)
# Get directions via public transit in JSON format.
# To return the result in XML format, change the Client response_format parameter to :xml.
result = directions.query(origin: '75 9th Ave, New York, NY',
destination: 'MetLife Stadium Dr East Rutherford, NJ 07073',
mode: 'transit',
departure_time: Time.now)
# Print the result
puts result
For more usage examples, check out the reference documentation.
Bug reports, Pull requests and Stars are always welcome. For bugs and feature requests, please create an issue.
The gem is available as open source under the terms of the MIT License.