Module: GoogleMapsService::Apis::Routes
- Included in:
- Client
- Defined in:
- lib/google_maps_service/apis/routes.rb
Overview
Performs requests to the Google Maps Routes API.
Constant Summary collapse
- ROUTES_BASE_URL =
Base URL of Google Maps Routes API
"https://routes.googleapis.com"
Instance Method Summary collapse
-
#compute_route_matrix(origins, destinations, field_mask: nil, travel_mode: nil, routing_preference: nil, departure_time: nil, arrival_time: nil, language_code: nil, region_code: nil, units: nil, extra_computations: nil, traffic_model: nil, transit_preferences: nil) ⇒ Object
Compute a route matrix.
-
#compute_routes(origin, destination, intermediates: nil, travel_mode: nil, routing_preference: nil, polyline_quality: nil, polyline_encoding: nil, departure_time: nil, arrival_time: nil, compute_alternative_routes: nil, route_modifiers: nil, language_code: nil, region_code: nil, units: nil, optimize_waypoint_order: nil, requested_reference_routes: nil, extra_computations: nil, traffic_model: nil, transit_preferences: nil, field_mask: nil) ⇒ Object
Compute routes between locations.
Instance Method Details
#compute_route_matrix(origins, destinations, field_mask: nil, travel_mode: nil, routing_preference: nil, departure_time: nil, arrival_time: nil, language_code: nil, region_code: nil, units: nil, extra_computations: nil, traffic_model: nil, transit_preferences: nil) ⇒ Object
Compute a route matrix
Only origins and destinations are required. The formats for each of the paramters are defined at developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRouteMatrix
matrix = gmaps.compute_route_matrix(
[
{waypoint: {address: 'South Brisbane, QLD, AU'}}
],
[
{waypoint: {address: 'Fitzroy, VIC, AU'}},
{waypoint: {address: 'Richmond, VIC, AU'}}
],
)
matrix = gmaps.compute_route_matrix(
[{waypoint: {address: 'South Brisbane, QLD, AU'}}],
[{waypoint: {address: 'Fitzroy, VIC, AU'}},{waypoint: {address: 'Richmond, VIC, AU'}}],
travel_mode: "TRANSIT",
departure_time: Time.now,
language_code: "en",
region_code: "AU",
units: "METRIC",
extra_computations: ["TOLLS"],
transit_preferences: {
allowedTravelModes: [ "RAIL" ],
routingPreference: "FEWER_TRANSFERS"
}
)
53 54 55 56 57 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 84 85 86 87 |
# File 'lib/google_maps_service/apis/routes.rb', line 53 def compute_route_matrix(origins, destinations, field_mask: nil, travel_mode: nil, routing_preference: nil, departure_time: nil, arrival_time: nil, language_code: nil, region_code: nil, units: nil, extra_computations: nil, traffic_model: nil, transit_preferences: nil) params = { origins: origins, destinations: destinations } params[:travelMode] = travel_mode if travel_mode params[:routingPreference] = routing_preference if routing_preference params[:departureTime] = time_convert(departure_time) if departure_time params[:arrivalTime] = time_convert(arrival_time) if arrival_time params[:languageCode] = language_code if language_code params[:regionCode] = region_code if region_code params[:units] = units if units params[:extraComputations] = extra_computations if extra_computations params[:trafficModel] = traffic_model if traffic_model params[:transitPreferences] = transit_preferences if transit_preferences field_mask ||= "*" post("/distanceMatrix/v2:computeRouteMatrix", params, base_url: ROUTES_BASE_URL, custom_response_decoder: method(:extract_routes_body), field_mask: field_mask) end |
#compute_routes(origin, destination, intermediates: nil, travel_mode: nil, routing_preference: nil, polyline_quality: nil, polyline_encoding: nil, departure_time: nil, arrival_time: nil, compute_alternative_routes: nil, route_modifiers: nil, language_code: nil, region_code: nil, units: nil, optimize_waypoint_order: nil, requested_reference_routes: nil, extra_computations: nil, traffic_model: nil, transit_preferences: nil, field_mask: nil) ⇒ Object
Compute routes between locations
Returns the primary route along with optional alternate routes, given a set of terminal and intermediate waypoints.
Only the origin and destination is required. The formats for each of the paramters are defined at developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes
route = gmaps.compute_routes(
{address: 'South Brisbane, QLD, AU'},
{address: 'Fitzroy, VIC, AU'}
)
route = gmaps.compute_routes(
{location: {latLng: {latitude: -27.4698, longitude: 153.0251}}},
{address: 'Fitzroy, VIC, AU'},
intermediates: [{address: 'Ultimo, NSW, AU'}],
travel_mode: 'DRIVE',
routing_preference: 'TRAFFIC_AWARE',
departure_time: Time.now + 3600,
language_code: 'en',
region_code: 'AU',
units: 'METRIC',
extra_computations: ['TOLLS'],
compute_alternative_routes: true
)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/google_maps_service/apis/routes.rb', line 139 def compute_routes(origin, destination, intermediates: nil, travel_mode: nil, routing_preference: nil, polyline_quality: nil, polyline_encoding: nil, departure_time: nil, arrival_time: nil, compute_alternative_routes: nil, route_modifiers: nil, language_code: nil, region_code: nil, units: nil, optimize_waypoint_order: nil, requested_reference_routes: nil, extra_computations: nil, traffic_model: nil, transit_preferences: nil, field_mask: nil) params = { origin: origin, destination: destination } params[:intermediates] = intermediates if intermediates params[:travelMode] = travel_mode if travel_mode params[:routingPreference] = routing_preference if routing_preference params[:polylineQuality] = polyline_quality if polyline_quality params[:polylineEncoding] = polyline_encoding if polyline_encoding params[:departureTime] = time_convert(departure_time) if departure_time params[:arrivalTime] = time_convert(arrival_time) if arrival_time params[:computeAlternativeRoutes] = compute_alternative_routes unless compute_alternative_routes.nil? params[:routeModifiers] = route_modifiers if route_modifiers params[:languageCode] = language_code if language_code params[:regionCode] = region_code if region_code params[:units] = units if units params[:optimizeWaypointOrder] = optimize_waypoint_order unless optimize_waypoint_order.nil? params[:requestedReferenceRoutes] = requested_reference_routes if requested_reference_routes params[:extraComputations] = extra_computations if extra_computations params[:trafficModel] = traffic_model if traffic_model params[:transitPreferences] = transit_preferences if transit_preferences field_mask ||= "*" post("/directions/v2:computeRoutes", params, base_url: ROUTES_BASE_URL, custom_response_decoder: method(:extract_routes_body), field_mask: field_mask) end |