Create a single-destination trip

This document describes how to create a single destination trip, set the correct fields, and assign it to a vehicle to fulfill. It assumes you have set up Fleet Engine and that you have created vehicles, have a working driver app, and optionally, a consumer app. See the following related guides for that:

Trip creation basics

This section describes the request details necessary for creating a trip in Fleet Engine. You issue a creation request using either gRPC and REST.

  • CreateTrip() method: gRPC or REST
  • CreateTripRequest message: gRPC only

Trip Fields

Use the following fields to create a trip in Fleet Engine. You can use different fields for the different kinds of trips: single- or multi-destination, back-to-back, or shared pooling trips. You can supply the optional fields when you create the trip, or you can set them later when you update the trip.

Trip fields
Name
Required?
Description
Yes
A string that includes the project ID. This ID must be the same ID used across your entire Fleet Engine integration, with the same service account roles.
Yes
A string that you create that uniquely identifies this trip. Trip IDs have certain restrictions, as indicated in the reference.
Yes
Set the TripType to the following values for the trip type you're creating:
  • Single destination: Set to SHARED or EXCLUSIVE .
  • Multi-destination: Set to EXCLUSIVE .
  • Back-to-back: Set to EXCLUSIVE .
  • Shared pooling: Set to SHARED .
Yes
The trip's point of origin.
Yes

Multi-destination trips only: The list of intermediate destinations that the driver visits in between pickup and drop-off. As with dropoff_point , this field can also be set later by calling UpdateTrip , but a multi-destination trip by definition contains intermediate destinations.

Yes

Shared-pooling trips only: This field supports interleaving the waypoints from multiple trips. It contains all of the remaining waypoints for the assigned vehicle, as well as the pickup and drop-off waypoints for this trip. You can set this field by calling CreateTrip or UpdateTrip . You can also update vehicle waypoints through the waypoints field with a call to UpdateVehicle . The service does not return this information on GetTrip calls due to privacy reasons.

No
The number of passengers on the trip.
No
The trip's destination.
No
The ID of the vehicle assigned to the trip.

Example: single-destination trip

The following example demonstrates how to create a trip to the Grand Indonesia East Mall. The trip involves two passengers, is exclusive, and its status is NEW . The provider_id of the trip must be the same as the Google Cloud project ID. The examples shows a Google Cloud Project with the project ID my-rideshare-co-gcp-project . This project must also include a service account in order to call Fleet Engine. See Service account roles for details.

  static 
  
 final 
  
 String 
  
 PROJECT_ID 
  
 = 
  
 "my-rideshare-co-gcp-project" 
 ; 
 TripServiceBlockingStub 
  
 tripService 
  
 = 
  
 TripService 
 . 
 newBlockingStub 
 ( 
 channel 
 ); 
 // Trip initial settings. 
 String 
  
 parent 
  
 = 
  
 "providers/" 
  
 + 
  
 PROJECT_ID 
 ; 
 Trip 
  
 trip 
  
 = 
  
 Trip 
 . 
 newBuilder 
 () 
  
 . 
 setTripType 
 ( 
 TripType 
 . 
 EXCLUSIVE 
 ) 
  
 // Use TripType.SHARED for carpooling. 
  
 . 
 setPickupPoint 
 ( 
  
 // Grand Indonesia East Mall. 
  
 TerminalLocation 
 . 
 newBuilder 
 (). 
 setPoint 
 ( 
  
 LatLng 
 . 
 newBuilder 
 () 
  
 . 
 setLatitude 
 ( 
 - 
 6.195139 
 ). 
 setLongitude 
 ( 
 106.820826 
 ))) 
  
 . 
 setNumberOfPassengers 
 ( 
 2 
 ) 
  
 // Provide the drop-off point if available. 
  
 . 
 setDropoffPoint 
 ( 
  
 TerminalLocation 
 . 
 newBuilder 
 (). 
 setPoint 
 ( 
  
 LatLng 
 . 
 newBuilder 
 () 
  
 . 
 setLatitude 
 ( 
 - 
 6.1275 
 ). 
 setLongitude 
 ( 
 106.6537 
 ))) 
  
 . 
 build 
 (); 
 // Create trip request 
 CreateTripRequest 
  
 createTripRequest 
  
 = 
  
 CreateTripRequest 
 . 
 newBuilder 
 () 
  
 . 
 setParent 
 ( 
 parent 
 ) 
  
 . 
 setTripId 
 ( 
 "trip-8241890" 
 ) 
  
 // Trip ID assigned by the provider. 
  
 . 
 setTrip 
 ( 
 trip 
 ) 
  
 // The initial state is NEW. 
  
 . 
 build 
 (); 
 // Error handling. 
 try 
  
 { 
  
 Trip 
  
 createdTrip 
  
 = 
  
 tripService 
 . 
 createTrip 
 ( 
 createTripRequest 
 ); 
 } 
  
 catch 
  
 ( 
 StatusRuntimeException 
  
 e 
 ) 
  
 { 
  
 Status 
  
 s 
  
 = 
  
 e 
 . 
 getStatus 
 (); 
  
 switch 
  
 ( 
 s 
 . 
 getCode 
 ()) 
  
 { 
  
 case 
  
 ALREADY_EXISTS 
 : 
  
 break 
 ; 
  
 case 
  
 PERMISSION_DENIED 
 : 
  
 break 
 ; 
  
 } 
  
 return 
 ; 
 } 
 

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: