{"id":26148885,"url":"https://github.com/skalar/google_distance_matrix","last_synced_at":"2025-04-05T16:10:48.648Z","repository":{"id":8210652,"uuid":"9645392","full_name":"Skalar/google_distance_matrix","owner":"Skalar","description":"Ruby client for The Google Distance Matrix API.","archived":false,"fork":false,"pushed_at":"2023-10-21T16:26:42.000Z","size":242,"stargazers_count":55,"open_issues_count":0,"forks_count":45,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-04-26T21:20:26.605Z","etag":null,"topics":["distancematrix","google-distance-matrix","matrix","ruby","ruby-client"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Skalar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-04-24T11:05:14.000Z","updated_at":"2024-06-19T09:58:45.242Z","dependencies_parsed_at":"2024-06-19T10:09:31.113Z","dependency_job_id":null,"html_url":"https://github.com/Skalar/google_distance_matrix","commit_stats":{"total_commits":200,"total_committers":13,"mean_commits":"15.384615384615385","dds":0.135,"last_synced_commit":"04912797454958fe3eda203b9e4715f87a1078dc"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skalar%2Fgoogle_distance_matrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skalar%2Fgoogle_distance_matrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skalar%2Fgoogle_distance_matrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skalar%2Fgoogle_distance_matrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Skalar","download_url":"https://codeload.github.com/Skalar/google_distance_matrix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361695,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distancematrix","google-distance-matrix","matrix","ruby","ruby-client"],"created_at":"2025-03-11T05:22:01.722Z","updated_at":"2025-04-05T16:10:48.621Z","avatar_url":"https://github.com/Skalar.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoogleDistanceMatrix\n\n![Build Status](https://github.com/Skalar/google_distance_matrix/workflows/Ruby/badge.svg)\n\nRuby client for the [Google Distance Matrix API](https://developers.google.com/maps/documentation/distance-matrix/intro).\n\nThis lib makes Google's distance matrix API easy to work with,\nallowing you to set up some origins and destinations and\npull the distance matrix from Google.\n\nOnce you have the matrix you can fetch all routes from a given\norigin or to a given destination.\n\n\n\n\n## Examples\n\n### Set up a matrix to work with\n\n```ruby\nmatrix = GoogleDistanceMatrix::Matrix.new\n```\n\n### Create some places to be used as origins or destinations for the matrix\n```ruby\nlat_lng = GoogleDistanceMatrix::Place.new lng: 12, lat: 12\naddress = GoogleDistanceMatrix::Place.new address: \"My address, Oslo\"\ndest_address = GoogleDistanceMatrix::Place.new address: \"Home, Oppegaard\"\n\n# Just an example of an object responding to lat \u0026 lng.\n# Point class isn't included in this gem, but feel free to\n# create your own point class or use something like https://github.com/nofxx/georuby\npoint_dest = Point.new lat: 1, lng: 2\ndest_object = GoogleDistanceMatrix::Place.new point_dest\n```\n### Add places to matrix's origins and destinations\n```ruby\nmatrix.origins \u003c\u003c lat_lng \u003c\u003c address\nmatrix.destinations \u003c\u003c dest_address \u003c\u003c dest_object\n\n# Added objects will be wrapped in a place automatically, so you may skip manyally creating Places.\nanother_point = Point.new lat: 1, lng: 3\nmatrix.origins \u003c\u003c another_point\n```\n### Do some configuration - see GoogleDistanceMatrix.configure_defaults as well.\n```ruby\nmatrix.configure do |config|\n  config.mode = 'driving'\n  config.avoid = 'tolls'\n\n  # To build signed URLs to use with a Google Business account.\n  config.google_business_api_client_id = \"123\"\n  config.google_business_api_private_key = \"your-secret-key\"\n\n  # If you have an API key, you can specify that as well.\n  config.google_api_key = \"YOUR_API_KEY\"\nend\n```\n### Get the data for the matrix\n\n`matrix.data` returns the data, loaded from Google, for this matrix.\n\n It is a multi dimensional array. Rows are ordered according to the values in the origins.\n Each row corresponds to an origin, and each element within that row corresponds to a pairing of the origin with a destination.\n\n\n### Query the matrix\n\nReturns an array of Google::DistanceMatrix::Route, all having given origin or destination.\n\n```ruby\nmatrix.routes_for dest_address\n```\n\nReturns Google::DistanceMatrix::Route with given origin and destination\n\n```ruby\nmatrix.route_for origin: lat_lng, destination: dest_address\n\n# Returns the shortest route to given destination, either by distance or duration\nmatrix.shortest_route_by_distance_to(dest_address)\nmatrix.shortest_route_by_duration_to(dest_address)\n\n# If your matrix is for driving and you provided a departure_time all Route objects within\n# the matrix will have duration_in_traffic_in_seconds. We can query the matrix for this data as well:\nmatrix.shortest_route_by_duration_in_traffic_to(dest_address)\n```\n\nIn cases where you built the place with an object (not hash with attributes) you may provide that object\nas well asking for routes. This is true for `route_for` and `shortest_route_by_*` as well.\n\n```ruby\nmatrix.routes_for point_dest # Returns routes for dest_object\n```\n\nYou may call query methods with a bang, in which case it will fail with an error if not all of the\nroutes in your result set for the called method are ok.\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'google_distance_matrix'‚ '~\u003e 0.7.0'\n```\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install google_distance_matrix\n\n\n### Ruby 2.x support\n\nLegacy systems that needs to run on unsupported rubies can depend on `v0.6.7`, which is the last supported version for Ruby 2.\n\n```ruby\ngem 'google_distance_matrix', '0.6.7'\n```\n\n\n## Configuration\n\nConfiguration is done directly on a matrix or via `GoogleDistanceMatrix.configure_defaults`.\nApart from configuration on requests it is also possible to provide your own logger class and\nset a cache.\n\n### Shorting the URL using encoded coordinates\nInstead of lat and lng values in the URL it is possible to use encoded set of coordinates\nusing the Encoded Polyline Algorithm. This is particularly useful if you have a large\nnumber of origin points, because the URL is significantly shorter when\nusing an encoded polyline.\n\n```ruby\nGoogleDistanceMatrix.configure_defaults do |config|\n  config.use_encoded_polylines = true\nend\n```\n\n\n### Request cache\n\nGiven Google's limit to the service you may have the need to cache requests. This is done by simply\nusing URL as cache keys. Cache we'll accept should provide a default ActiveSupport::Cache::Store interface.\n\n```ruby\nGoogleDistanceMatrix.configure_defaults do |config|\n  config.cache = ActiveSupport::Cache.lookup_store :your_store, {\n    expires_in: 12.hours\n    # ..or other options you like for your store\n  }\nend\n```\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskalar%2Fgoogle_distance_matrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskalar%2Fgoogle_distance_matrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskalar%2Fgoogle_distance_matrix/lists"}