什么是按需行程?
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本部分中的文档介绍了如何使用 Google Maps Mobility 按需出行服务创建和处理行程。本教程假定您熟悉以下内容:
您将使用的 TripService
可用于 gRPC 和 REST。为简单起见,字段引用遵循 gRPC 惯例。
在 Fleet Engine 中,对于按需服务,行程是一种旅程类型,用于模拟食品配送或乘客乘车请求的完成情况。行程具有一个状态,您需要在行程进展过程中向 Fleet Engine 报告该状态,例如 NEW
、ENROUTE_TO_PICKUP
等。行程状态与分配给车辆的地理定位途经点相对应,并且 Fleet Engine 会根据您所做的每次行程更新来修改这些车辆途经点。如需详细了解行程及其与车辆的关系,请参阅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 提供行程详细信息和车辆位置信息,而 Consumer SDK 会使用监听器接收行程更新并在消费者应用中显示这些信息。Fleet Engine 会自动更新预计到达时间、剩余距离、路线和剩余车辆途经点。如需了解详情,请参阅共享行程(对于按需行程)。 |
5 |
完整行程。 |
当车辆到达行程的目的地航点且司机表明行程成功完成时,您的系统会在 Fleet Engine 中将 TripStatus 设置为 COMPLETE 。请注意,与车辆类似,无论状态如何,行程实体在 Fleet Engine 中都会保持活跃状态 7 天,之后会被移除。 |
行程序列流程
下图更详细地展示了此流程。

后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-12。
[null,null,["最后更新时间 (UTC):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)"]]