The Consumer SDK provides a turnkey capability for ridesharing consumer apps to display the location and progress of the vehicle taking them on their journey.
Some Rideshare Providers, however, want more control over their end-user customer experience with flexible integration, while still taking advantage of Google’s accurate and real-time vehicle location, ETA, and route. This guide shows you how to retrieve trip data directly from Fleet Engine, as an alternative to using the Consumer SDK.
Overview
To retrieve trip information from Fleet Engine directly, call the GetTrip
method, specifying the JOURNEY_SHARING_V1S view
(RPC
|
REST).
static final String PROJECT_ID = "my-rideshare-co-gcp-project";
static final String TRIP_ID = "trip-A";
String tripName = "providers/" + PROJECT_ID + "/trips/" + TRIP_ID;
GetTripRequest getTripRequest =
GetTripRequest.newBuilder()
.setName(tripName)
.setView(JOURNEY_SHARING_V1S)
.build();
Trip trip = tripService.getTrip(getTripRequest);
The resulting Trip (RPC | REST) object will have the following fields populated with the latest available information for the Trip:
name
vehicle_id
trip_status
trip_type
number_of_passengers
pickup_point
actual_pickup_point
pickup_time
intermediate_destinations
intermediate_destinations_version
intermediate_destination_index
dropoff_point
actual_dropoff_point
dropoff_time
remaining_waypoints
last_location
view
(== JOURNEY_SHARING_V1S)
Rideshare providers typically poll the trip service for the status of each trip
every two to five seconds while the rider is actively monitoring vehicle
progress. Vehicle location updates are typically at a longer interval, such as
10 seconds. The Trip.last_location.update_time
field can be monitored to see
if there have been any updates since the previous call to GetTrip
.
Trip waypoints
The Trip entity contains a repeated field of type TripWaypoint
(RPC
|
REST).
This field includes all waypoints that the vehicle will need to travel, in
order, before this trip's final drop-off point. Specifying the Journey Sharing
view tells Fleet Engine to put updated information in the remaining_waypoints[0]
TripWaypoint
. In other, non-Journey Sharing views, that waypoint does not
usually reflect the latest position of the assigned vehicle.
Here is an example of Trip A's remaining_waypoints
field:
| |||||||||||||||||||||
|
With back-to-back and shared (carpool) trips, this list may contain waypoints
from other trips that will be traversed during this trip. For example, consider
the scenario where Trip B is assigned to the same vehicle as Trip A. The
remaining_waypoints
field for Trip A would then be populated as follows.
(Most of the fields have been omitted for conciseness, but they would be
populated consistent with the previous example.)
[0] | trip_id = "trip_A" |
---|---|
waypoint_type = PICKUP_WAYPOINT_TYPE | |
[1] | trip_id = "trip_B" |
waypoint_type = PICKUP_WAYPOINT_TYPE | |
[2] | trip_id = "trip_B" |
waypoint_type = DROP_OFF_WAYPOINT_TYPE | |
[3] | trip_id = "trip_A" |
waypoint_type = DROP_OFF_WAYPOINT_TYPE |
Trip B's remaining_waypoint
field would be populated similarly, but only the
first three entries would be present, since Trip A's dropoff point is not part
of Trip B's route.