Retrieve trip data directly from Fleet Engine

This guide shows you how to retrieve trip data directly from Fleet Engine, as an alternative to using the Consumer SDK. You can use this approach for more control over your end-user experience while still taking advantage of Fleet Engine's accurate and real-time vehicle location, ETA, and routing.

For details on using the Consumer SDK, see Share journeys for on-demand trips.

Retrieve trip information

To retrieve trip information from Fleet Engine directly, call the GetTrip method, specifying the JOURNEY_SHARING_V1S view. See reference for RPC or REST.

Your server would typically poll the trip service for the status of each trip while the rider is actively monitoring vehicle progress. Vehicle location updates typically occur every 10 seconds and your system should poll at that same rate. The Trip.last_location.update_time field can be monitored to see if there have been any updates since the previous call to GetTrip.

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 object has the following fields populated with the latest available information for the trip:

name trip_status remaining_waypoints
vehicle_id trip_type last_location
number_of_passengers pickup_point view (== JOURNEY_SHARING_V1S)
actual_pickup_point intermediate_destinations intermediate_destination_index
pickup_time intermediate_destinations_version dropoff_point
actual_dropoff_point dropoff_time

Retrieve remaining trip waypoints

The Trip entity contains a repeated field of type TripWaypoint 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. See the reference for RPC or REST.

For more information, see Trip status and remaining vehicle waypoints in the Introduction to trips guide.

Here is an example of the remaining_waypoints field for a trip, Trip A:

[0] location.point = trip.pickup_point.point
trip_id = "trip_A"
waypoint_type = PICKUP_WAYPOINT_TYPE
path_to_waypoint = LatLng[] 1st LatLng from remaining path to pickup
2nd LatLng from remaining path to pickup
...
last LatLng from remaining path to pickup
pickup_point, if different from last
traffic_data
distance_meters = distance from current vehicle_location along path_to_waypoint to pickup
eta = updated ETA
duration = updated duration
[1] location.point = trip.dropoff_point.point
trip_id = "trip_A"
waypoint_type = DROP_OFF_WAYPOINT_TYPE
path_to_waypoint = LatLng[] 1st LatLng from dropoff leg
2nd LatLng from dropoff leg
...
last LatLng from dropoff leg
dropoff_point, if different from last
traffic_data
distance_meters = distance from pickup along path_to_waypoint to dropoff
eta = updated ETA
duration = drop-off leg duration

With back-to-back and shared pooling trips, this list may contain waypoints from other trips to be traversed before this journey. 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 drop-off point is not part of Trip B's route.