Ruby Client for Google Maps Services
Description
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.
Please make sure you are using the latest release to get the newest features.
Requirements
- Ruby 2.1 or later.
- A Google Maps API key.
- Client ID and Client Secret (for Google Maps APIs Premium Plan customers).
Installation
Add this line to your application's Gemfile:
gem 'googlemaps-services'
And then execute:
$ bundle
Or install it yourself as:
$ gem install googlemaps-services
Documentation
View the reference documentation.
Usage
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.
Contributing
Bug reports, Pull requests and Stars are always welcome. For bugs and feature requests, please create an issue.
Donate
License
The gem is available as open source under the terms of the MIT License.