Ruby Client for Google Maps Services

Gem Version Build Status Dependency Status Code Climate Coverage Status

This is porting of Python Client for Google Maps Services.

Description

Use Ruby? Want to geocode something? Looking for directions? Maybe matrices of directions? This library brings the Google Maps API Web Services to your Ruby application. Analytics

The Ruby Client for Google Maps Services is a Ruby Client library for the following Google Maps APIs:

Keep in mind that the same terms and conditions apply to usage of the APIs when they're accessed through this library.

Support

This library is community supported. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it. We will try to support, through Stack Overflow, the public and protected surface of the library and maintain backwards compatibility in the future; however, while the library is in version 0.x, we reserve the right to make backwards-incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), our intention is to deprecate and give developers a year to update their code.

If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.

Requirements

  • Ruby 2.0 or later.
  • A Google Maps API key.

API keys

Each Google Maps Web Service requires an API key or Client ID. API keys are freely available with a Google Account at https://developers.google.com/console. To generate a server key for your project:

  1. Visit https://developers.google.com/console and log in with a Google Account.
  2. Select an existing project, or create a new project.
  3. Click Enable an API.
  4. Browse for the API, and set its status to "On". The Python Client for Google Maps Services accesses the following APIs:
    • Directions API
    • Distance Matrix API
    • Elevation API
    • Geocoding API
    • Time Zone API
    • Roads API
  5. Once you've enabled the APIs, click Credentials from the left navigation of the Developer Console.
  6. In the "Public API access", click Create new Key.
  7. Choose Server Key.
  8. If you'd like to restrict requests to a specific IP address, do so now.
  9. Click Create.

Your API key should be 40 characters long, and begin with AIza.

Important: This key should be kept secret on your server.

Installation

$ gem install google_maps_service

Developer Documentation

View the reference documentation

Additional documentation for the included web services is available at https://developers.google.com/maps/.

Usage

This example uses the Geocoding API.

gmaps = GoogleMapsService::Client.new(key: 'Add Your Key here')

# Geocoding and address
geocode_result = gmaps.geocode(address: '1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode(latlng: [40.714224, -73.961452])

# Request directions via public transit
now = Time.now
directions_result = gmaps.directions(origin: "Sydney Town Hall",
                                     destination: "Parramatta, NSW",
                                     mode: "transit",
                                     departure_time: now)

For more usage examples, check out the tests.

Contributing

  1. Fork it ( https://github.com/edwardsamuel/google-maps-services-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request