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](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand).

## 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](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1.md.txt#tripview) or
[REST](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.trips.md.txt#tripview).

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`.

```java
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](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1.md.txt#tripwaypoint) or [REST](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/TripWaypoint.md.txt).

For more information, see [Trip status and remaining vehicle waypoints](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/trip-intro.md.txt#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" |
| \[0\] |
|---|---|
| waypoint_type = PICKUP_WAYPOINT_TYPE |
| \[1\] | trip_id = "trip_B" |
| \[1\] | waypoint_type = PICKUP_WAYPOINT_TYPE |
| \[2\] | trip_id = "trip_B" |
| \[2\] | waypoint_type = DROP_OFF_WAYPOINT_TYPE |
| 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.

> [!NOTE]
> **Note:** Carefully consider privacy implications when displaying waypoints of trips other than the current user's.