Skip to content

Provides travel distance and time for a matrix of origins and destinations

License

Notifications You must be signed in to change notification settings

soylent/google-apis-distance_matrix

Repository files navigation

Google Distance Matrix API Client

The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points.

https://developers.google.com/maps/documentation/distance-matrix/start

Usage

require 'google/apis/distance_matrix'

distance_matrix = Google::Apis::DistanceMatrix::DistanceMatrixService.new
distance_matrix.key = '<GOOGLE_API_KEY>'

pp distance_matrix.distance(origins: 'Washington, DC', destinations: 'New York, NY')
# #<Google::Apis::DistanceMatrix::DistanceMatrixData:0x00007fc59a2828c0
#  @destination_addresses=["New York, NY, USA"],
#  @origin_addresses=["Washington, DC, USA"],
#  @rows=
#   [#<Google::Apis::DistanceMatrix::Row:0x00007fc59a250ff0
#     @elements=
#      [#<Google::Apis::DistanceMatrix::Element:0x00007fc59a2502a8
#        @distance=
#         #<Google::Apis::DistanceMatrix::Distance:0x00007fc59a24b7d0
#          @text="362 km",
#          @value=361957>,
#        @duration=
#         #<Google::Apis::DistanceMatrix::Duration:0x00007fc59a24a1c8
#          @text="3 hours 51 mins",
#          @value=13840>,
#        @status="OK">]>],
#  @status="OK">

Installation

  • Add this line to your Gemfile

    gem 'google-apis-distance_matrix', '~> 0.1'
  • And then execute

    bundle
    

Development

The client was generated by the google-api-client gem.

https://github.com/googleapis/google-api-ruby-client#generating-apis

  • Install dependencies

    $ bundle
    
  • Create .env file

    $ echo "GOOGLE_API_KEY=<YOUR_KEY>" > .env
    
  • Run tests

    $ bundle exec rake
    
  • Build the gem

    $ bundle exec rake build
    

About

Provides travel distance and time for a matrix of origins and destinations

Topics

Resources

License

Stars

Watchers

Forks

Languages