module Azimuth::Client::RouteMatrix
Methods for the Route Matrix API
Public Instance Methods
route_matrix(locations, options={})
click to toggle source
Get calculation of the distances and driving times between locations. @param locations [Array] the locations @param options [Hash] optional parameters @option options [Hash] :manyToOne parameter @option options [Hash] :allToAll parameter @return [Hashie::Mash] the locations and their distance and traveling time @see www.mapquestapi.com/directions/#matrix @example
Azimuth.route_matrix(['48.843079, 2.314442', '48.869061, 2.383329']
# File lib/azimuth/client/route_matrix.rb, line 16 def route_matrix(locations, options={}) parameters = { locations: locations, options: options } format_response(post('routematrix', parameters)) end
Private Instance Methods
delete_first_location_from_response(response)
click to toggle source
# File lib/azimuth/client/route_matrix.rb, line 37 def delete_first_location_from_response(response) [:locations, :time, :distance].each do |info| response.public_send(info).delete_at(0) end end
format_response(response)
click to toggle source
# File lib/azimuth/client/route_matrix.rb, line 24 def format_response(response) delete_first_location_from_response(response) unless response.allToAll response.locations.each_with_index.map do |location, i| Hashie::Mash.new( latitude: location.latLng.lat, longitude: location.latLng.lng, time: response.time[i], distance: response.distance[i] ) end end