Module: GoogleMapsApis::Services::Directions
- Included in:
- Client
- Defined in:
- lib/google_maps_apis/services/directions.rb
Overview
Performs requests to the Google Maps Directions API.
Instance Method Summary collapse
-
#directions(origin, destination, mode: nil, waypoints: nil, alternatives: false, avoid: nil, language: nil, units: nil, region: nil, departure_time: nil, arrival_time: nil, optimize_waypoints: false, transit_mode: nil, transit_routing_preference: nil) ⇒ Array
Get directions between an origin point and a destination point.
Instance Method Details
#directions(origin, destination, mode: nil, waypoints: nil, alternatives: false, avoid: nil, language: nil, units: nil, region: nil, departure_time: nil, arrival_time: nil, optimize_waypoints: false, transit_mode: nil, transit_routing_preference: nil) ⇒ Array
Get directions between an origin point and a destination point.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/google_maps_apis/services/directions.rb', line 62 def directions(origin, destination, mode: nil, waypoints: nil, alternatives: false, avoid: nil, language: nil, units: nil, region: nil, departure_time: nil, arrival_time: nil, optimize_waypoints: false, transit_mode: nil, transit_routing_preference: nil) params = { origin: GoogleMapsApis::Convert.waypoint(origin), destination: GoogleMapsApis::Convert.waypoint(destination) } params[:mode] = GoogleMapsApis::Validator.travel_mode(mode) if mode if waypoints = waypoints waypoints = GoogleMapsApis::Convert.as_list(waypoints) waypoints = waypoints.map { |waypoint| GoogleMapsApis::Convert.waypoint(waypoint) } waypoints = ['optimize:true'] + waypoints if optimize_waypoints params[:waypoints] = GoogleMapsApis::Convert.join_list("|", waypoints) end params[:alternatives] = 'true' if alternatives params[:avoid] = GoogleMapsApis::Convert.join_list('|', avoid) if avoid params[:language] = language if language params[:units] = units if units params[:region] = region if region 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/directions/json', params)[:routes] end |