Module: GoogleMapsApis::Services::DistanceMatrix
- Included in:
- Client
- Defined in:
- lib/google_maps_apis/services/distance_matrix.rb
Overview
Performs requests to the Google Maps Distance Matrix API.
Instance Method Summary collapse
-
#distance_matrix(origins, destinations, mode: nil, language: nil, avoid: nil, units: nil, departure_time: nil, arrival_time: nil, transit_mode: nil, transit_routing_preference: nil) ⇒ Hash
Gets travel distance and time for a matrix of origins and destinations.
Instance Method Details
#distance_matrix(origins, destinations, mode: nil, language: nil, avoid: nil, units: nil, departure_time: nil, arrival_time: nil, transit_mode: nil, transit_routing_preference: nil) ⇒ Hash
Gets travel distance and time for a matrix of origins and destinations.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/google_maps_apis/services/distance_matrix.rb', line 58 def distance_matrix(origins, destinations, mode: nil, language: nil, avoid: nil, units: nil, departure_time: nil, arrival_time: nil, transit_mode: nil, transit_routing_preference: nil) params = { origins: GoogleMapsApis::Convert.waypoints(origins), destinations: GoogleMapsApis::Convert.waypoints(destinations) } params[:language] = language if language params[:mode] = GoogleMapsApis::Validator.travel_mode(mode) if mode params[:avoid] = GoogleMapsApis::Validator.avoid(avoid) if avoid params[:units] = units if units params[:departure_time] = GoogleMapsApis::Convert.time(departure_time) if departure_time params[:arrival_time] = GoogleMapsApis::Convert.time(arrival_time) if arrival_time if departure_time and arrival_time raise ArgumentError, 'Should not specify both departure_time and arrival_time.' end params[:transit_mode] = GoogleMapsApis::Convert.join_list('|', transit_mode) if transit_mode params[:transit_routing_preference] = transit_routing_preference if transit_routing_preference return get('/maps/api/distancematrix/json', params) end |