什麼是隨選行程?
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本節文件說明如何使用 Google 地圖隨選行程服務建立及處理行程。並假設您熟悉下列項目:
您使用的 TripService
適用於 gRPC 和 REST。為求簡化,欄位參照會遵循 gRPC 慣例。
在 Fleet Engine On Demand Rides and Deliveries 中,行程是一種旅程,可模擬消費者提出的餐點外送或叫車要求。行程有狀態,您會在行程進展時向 Fleet Engine 回報狀態,例如 NEW
、ENROUTE_TO_PICKUP
等。行程狀態對應於指派給車輛的地理位置航點,而 Fleet Engine 會在您每次更新行程時修改這些車輛航點。如要進一步瞭解行程及其與車輛的關係,請參閱車隊引擎基礎知識中的「隨選行程」。
行程的生命週期
如要在 Fleet Engine 中追蹤每趟行程,您必須先建立 Trip
實體。如需參考資料,請參閱 gRPC 或 REST。
下表說明在系統中建立行程的端對端流程範例,以及 Fleet Engine 中的生命週期階段。本文假設您已設定 Fleet Engine,且有車輛可指派給行程,並在駕駛人應用程式中啟用位置資訊更新功能。請參閱「Driver SDK:隨選行程」。
1 |
接收預訂要求。 |
在 Fleet Engine 行程開始前,預訂系統會先透過應用程式或其他預訂系統,收到消費者提出的叫車或送貨要求。然後,系統會使用 CreateTrip 建立行程實體,並填入必要欄位,例如取貨地點。此時,應用程式也可以設定其他欄位,例如乘客和下車地點,或等到指派車輛後再設定。請參閱「建立單一目的地的行程」。 |
2 |
指派車輛。 |
您可以直接在系統中將車輛指派給行程,並向 Fleet Engine 回報指派情形,也可以使用「搜尋車輛」服務搜尋車輛,並依行程和車輛屬性篩選,找出最適合完成行程的車輛。搜尋半徑內的任何線上車輛,都會透過 Driver SDK 提供的定位更新資訊,告知使用者車輛位置。
SearchVehicle 傳回與行程相符的車輛後,系統會呼叫 UpdateTrip 端點,回報指派給 NEW 行程的車輛 ID。
|
3 |
更新行程。 |
司機接受行程並開始導航前往上車地點後,系統會將行程狀態從 NEW 更新為 ENROUTE_TO_PICKUP 。在整個行程中,您會持續輪詢車輛位置,方法是直接從應用程式連線至後端,或是輪詢 Fleet Engine,後者會從 Driver SDK 接收持續的車輛位置更新串流。系統接著會向 Fleet Engine 回報每個行程里程碑,後者會據此更新車輛的途經點清單。
|
4 |
與消費者分享歷程。 |
Fleet Engine 會將行程詳細資料和車輛位置資訊提供給 Consumer SDK,後者會使用接聽程式接收行程更新,並在消費者應用程式中顯示這些資訊。Fleet Engine 會自動更新預計抵達時間、剩餘距離、路線和車輛剩餘路線控點。詳情請參閱「共乘行程 (隨選行程)」。 |
5 |
完成行程。 |
車輛抵達行程的目的地航點,且駕駛人指出行程順利完成後,系統會在 Fleet Engine 中將 TripStatus 設為 COMPLETE 。請注意,與車輛一樣,行程實體會在 Fleet Engine 中保留 7 天 (不論狀態為何),之後就會移除。 |
行程序列流程
下圖更詳細地說明這個流程。

後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-12 (世界標準時間)。
[null,null,["上次更新時間:2025-08-12 (世界標準時間)。"],[[["\u003cp\u003eThis documentation provides a comprehensive guide on utilizing the Google Maps Mobility on-demand trips service for managing and tracking trips.\u003c/p\u003e\n"],["\u003cp\u003eYou should have a foundational understanding of Fleet Engine, Vehicle Basics, and Trip Basics for on-demand services.\u003c/p\u003e\n"],["\u003cp\u003eFleet Engine's \u003ccode\u003eTripService\u003c/code\u003e enables the creation, assignment, updating, and completion of trips through gRPC or REST.\u003c/p\u003e\n"],["\u003cp\u003eTrips represent journeys fulfilling consumer requests, evolving through various statuses like \u003ccode\u003eNEW\u003c/code\u003e, \u003ccode\u003eENROUTE_TO_PICKUP\u003c/code\u003e, and \u003ccode\u003eCOMPLETE\u003c/code\u003e, influencing vehicle waypoints.\u003c/p\u003e\n"],["\u003cp\u003eThe trip lifecycle includes booking, vehicle assignment, status updates, consumer journey sharing, and completion, all managed through Fleet Engine interactions.\u003c/p\u003e\n"]]],[],null,["The documentation in this section shows how to create and work with trips using\nthe Google Maps Mobility on-demand trips service. It assumes familiarity with\nthe following:\n\n- **Fleet Engine** : You should be familiar with Fleet Engine implementation details, request mechanisms, and security. For that, see [What is the Fleet\n Engine service?](/maps/documentation/mobility/fleet-engine/essentials) and the security topics in [Set up Fleet Engine](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet).\n- **Vehicles basics** for on-demand services. See [Introduction to vehicles](/maps/documentation/mobility/fleet-engine/essentials/vehicles-intro).\n- **Trip basics** for on-demand services. See [On-demand trips](/maps/documentation/mobility/fleet-engine/essentials/trip-intro).\n\nThe `TripService` that you'll use is available for [gRPC](/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1#tripservice) and [REST](/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.trips).\nFor simplicity sake, field references follow the gRPC convention.\n\nIn Fleet Engine for on-demand services, a trip is a type of journey that models\nthe fulfillment of a food delivery or ride request from your consumers. A trip\nhas a status that you report to Fleet Engine as the journey evolves, such as\n`NEW`, `ENROUTE_TO_PICKUP`, and more. The trip status corresponds to geo-located\nwaypoints assigned to the vehicle, and Fleet Engine modifies these vehicle\nwaypoints with each trip update you make. See [On demand trips](/maps/documentation/mobility/fleet-engine/essentials/trip-intro) in **Fleet\nEngine essentials** for more about trips and their relationship to vehicles.\n\nLife of a trip\n\nIn order to track each trip in Fleet Engine, you must first create a `Trip`\nentity. See either [gRPC](/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1#maps.fleetengine.v1.Trip) or [REST](/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.trips) for reference.\n\nThe following table describes an example end-to-end flow of a trip created in\nyour system and its lifecycle stages in Fleet Engine. It assumes you have set up\nFleet Engine and have a vehicle to assign to the trip, with location updates\nenabled in the driver app. See [Driver SDK: On-demand trips](/maps/documentation/mobility/driver-sdk/on-demand).\n\n|---|----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 1 | **Receive booking request.** | Before a Fleet Engine trip begins, your booking system first receives a request for a ride or delivery from a consumer through your app or other booking system. Your system then creates the trip entity using `CreateTrip` with required fields, such as the pickup location. It can also set other fields at this point, such passengers and dropoff location, or wait until it assigns a vehicle. See [Create a single-destination trip](/maps/documentation/mobility/fleet-engine/journeys/trips/create-trip). |\n| 2 | **Assign vehicle.** | You can either assign vehicles to trips directly within your system and report the assignment to Fleet Engine, or you can use the [Search Vehicle](/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-search-vehicle) service to search for vehicles, filtering by both trip and vehicle attributes to find the best vehicle to complete the journey. Any online vehicle within your search radius makes their proximity known through location updates provided by the Driver SDK. Once `SearchVehicle` returns a vehicle that you match to a trip, your system calls the `UpdateTrip` endpoint to report the vehicle ID you assigned to the `NEW` trip. |\n| 3 | **Update trip.** | Once the driver accepts the trip and begins navigating to the pickup location, your system updates the trip status from `NEW` to `ENROUTE_TO_PICKUP`. You continue to poll the vehicle location throughout the journey, either through a direct connection from the app to your backend, or by polling Fleet Engine, which receives an ongoing stream of vehicle location updates from the Driver SDK. Your system then reports each journey milestone to Fleet Engine, which updates the vehicle's waypoint list accordingly. |\n| 4 | **Share journey with consumer.** | Fleet Engine makes trip details and vehicle location available to the Consumer SDK, which uses a listener to receive trip updates and display them in the consumer app. Fleet Engine automatically updates ETA, remaining distance, routes, and remaining vehicle waypoints. See [Share journeys for on-demand trips](/maps/documentation/mobility/journey-sharing/on-demand) for more information. |\n| 5 | **Complete trip.** | Once the vehicle reaches the destination waypoint of the trip and your driver indicates a successful trip, your system sets the `TripStatus` to `COMPLETE` in Fleet Engine. Keep in mind that, like vehicles, trip entities remain active within Fleet Engine for 7 days regardless of status, at which point they are removed. |\n\nTrip sequence flow\n\nThe following diagram shows a more detailed view of this flow.\n\nWhat's next\n\n- [Create a single-destination trip](/maps/documentation/mobility/fleet-engine/journeys/trips/create-trip)"]]