Module: GoogleMapsService::Apis::Directions
- Included in:
- Client
- Defined in:
- lib/google_maps_service/apis/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_service/apis/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: GoogleMapsService::Convert.waypoint(origin), destination: GoogleMapsService::Convert.waypoint(destination) } params[:mode] = GoogleMapsService::Validator.travel_mode(mode) if mode if waypoints = waypoints waypoints = GoogleMapsService::Convert.as_list(waypoints) waypoints = waypoints.map { |waypoint| GoogleMapsService::Convert.waypoint(waypoint) } waypoints = ['optimize:true'] + waypoints if optimize_waypoints params[:waypoints] = GoogleMapsService::Convert.join_list("|", waypoints) end params[:alternatives] = 'true' if alternatives params[:avoid] = GoogleMapsService::Convert.join_list('|', avoid) if avoid params[:language] = language if language params[:units] = units if units params[:region] = region if region params[:departure_time] = GoogleMapsService::Convert.time(departure_time) if departure_time params[:arrival_time] = GoogleMapsService::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] = GoogleMapsService::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 |