Coder Social home page Coder Social logo

google_maps_api-distance_matrix's Introduction

GoogleMapsAPI::DistanceMatrix

This is a wrapper around the Google Maps Distance Matrix API.

Installation

Add this line to your application's Gemfile:

gem 'google_maps_api-distance_matrix'

And then execute:

$ bundle

Or install it yourself as:

$ gem install google_maps_api-distance_matrix

Usage

GoogleMapsAPI::DistanceMatrix.calculate(origins, destinations, options = {})

Origins and destinations are arrays of strings or anything that supports to_ary. Options is a Symbols Hash with optional parameters. (See https://developers.google.com/maps/documentation/distancematrix/#RequestParameters for more information).

For Google Business/Enterprise requests, include the :key, :client and optionally, :channel in the options hash.

Examples:

origins = ["350, 5th Ave, NY", "100, 56th St, NY", [40.764291, -73.979169], ...]
destinations = ["673, 45th St, NY", [40.763641,-73.987473], ...]
options = {:language => 'pt'}
GoogleMapsAPI::DistanceMatrix.calculate(origins, destinations, options)
# => #<GoogleMapsAPI::DistanceMatrix::Response:0x00000001f2b510...>

The GoogleMapsAPI::DistanceMatrix::Response object mimics the API JSON structure.

Contributing

I am new to Ruby and Testing. We need better specs.

  1. Fork it ( https://github.com/zavan/google_maps_api-distance_matrix/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

Important

  • Do not touch the version;
  • Write specs for new features;
  • Be independent of Rails stuff;
  • All specs must pass.

Also see

google_maps_api-distance_matrix's People

Contributors

zavan avatar aleksandrpanteleymonov avatar

Stargazers

Mohamad Kaakati avatar Harshith s avatar Ashu patel avatar Vitalii Shvedchenko avatar Oguzhan ilhan avatar Tom de Grunt avatar

Watchers

James Cloos avatar  avatar Ashu patel avatar

google_maps_api-distance_matrix's Issues

Broken API

Hi !

I'm using rails 4.2.6 with Ruby 2.3.0
When attempting to use your gem from rails console:


origins = [[2.85800005014191, 50.4953248662245]] 
destinations =  [[2.85773780193996, 50.49494146317214], [2.854084019245316, 50.48937560068271], [2.867151912465668, 50.495960836073216]] 
options = { key: 'my-api-key', https: true }

It fails:

2.3.0 :015 > GoogleMapsAPI::DistanceMatrix.calculate(origins, destinations, options)
NoMethodError: undefined method `[]' for nil:NilClass
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-core-0.2.0/lib/google_maps_api/core/metric.rb:18:in `from_hash'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/element.rb:13:in `from_hash'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/row.rb:16:in `block in build_elements'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/row.rb:15:in `collect'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/row.rb:15:in `build_elements'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/row.rb:9:in `from_hash'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/response.rb:34:in `block in build_rows'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/response.rb:33:in `collect'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/response.rb:33:in `build_rows'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/response.rb:16:in `from_json'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix/request.rb:25:in `perform'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/google_maps_api-distance_matrix-0.2.1/lib/google_maps_api/distance_matrix.rb:13:in `calculate'
  from (irb):15
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
... 7 levels...
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/commands/rails.rb:6:in `call'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/command_wrapper.rb:38:in `call'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application.rb:185:in `block in serve'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application.rb:156:in `fork'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application.rb:156:in `serve'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application.rb:131:in `block in run'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application.rb:125:in `loop'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application.rb:125:in `run'
  from /home/kofronpi/myfolder/myproject/.bundle/ruby/2.3.0/gems/spring-1.6.4/lib/spring/application/boot.rb:18:in `<top (required)>'
  from /home/kofronpi/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from /home/kofronpi/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from -e:1:in `<main>'2.3.0 :016 > 

Cannot require lib

Hi! Cool gem.

I cannot require it though.
I've tried with
gem 'google_maps_api-distance_matrix', '~> 0.2.2', require: true
and
gem 'google_maps_api-distance_matrix', '~> 0.2.2', require: 'google_maps_api'

In both cases I get require': cannot load such file -- ... (LoadError)

I'm using Rails 5.1.2, and Ruby 2.4.1

If you know what I'm doing wrong please let me know. Thank you!

Also, does the gem take care of diving into more than one request in case there are more points than the google allowed dimensions for the cost matrix?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.