即時道路資料會提供所選路線的最新路況和事件資訊,支援動態監控和快速回應。這項資料與 BigQuery 中定期收集的資料不同,適用於需要即時資訊的案例。
這項資料會持續串流,包括行程時間長度 (顯示路線上的行車時間) 和速度讀取間隔 (顯示路線上的車流密度)。
如要存取即時道路資料,合約必須包含「即時作業」套件。
建立「旅行時間和速度讀取間隔」Pub/Sub 訂閱項目
我們會提供專屬的 Google Cloud Pub/Sub 主題,您可以在這些主題中訂閱所有已建立路線的即時資料。
下列程式碼範例顯示使用二進位編碼的主題格式:
projects/maps-platform-roads-management/topics/rmi-roadsinformation-PROJECT_NUMBER
我們也提供另一個使用 JSON 編碼的主題 (後方加上 -json)。您必須訂閱我們提供給您的 Pub/Sub 主題,才能接收即時資料訊息。如要快速瞭解如何訂閱及取用 Cloud Pub/Sub 主題的訊息,請參閱「訂閱主題」。
旅行時間和速度讀取間隔結構定義
每則即時資料訊息都包含下列資料:
- 道路詳細資料,例如
duration_in_seconds、static_duration_in_seconds、speed_reading_offsets(以偏移量為準的速度讀取間隔) 和retrieval_timestamp。 - 路線 ID,例如
selected_route_id和display_name。
每則訊息都會按照下列 Protobuf 格式發布。
syntax = "proto3"; // Contains the road information like travel duration and speed reading // intervals for a selected route. message RoadsInformation { // Legacy message. May stop being populated on or after November 9, 2026. // Use top-level duration_in_seconds and static_duration_in_seconds instead. message TravelDuration { // The duration of travel through the route based on current road // conditions. float duration_in_seconds = 1; // The duration of travel through the route without taking road // conditions into consideration. float static_duration_in_seconds = 2; } message Timestamp { // Represents seconds of UTC time since Unix epoch // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to // 9999-12-31T23:59:59Z inclusive. int64 seconds = 1; // Non-negative fractions of a second at nanosecond resolution. Negative // second values with fractions must still have non-negative nanos values // that count forward in time. Must be from 0 to 999,999,999 // inclusive. int32 nanos = 2; } // Legacy message representing the latitude and longitude of a coordinate // within a coordinate-based speed reading interval. message LatLng { float latitude = 1; float longitude = 2; } // Legacy coordinate-based speed reading interval message. May stop being // populated on or after November 9, 2026. Use SpeedReadingOffset instead. message SpeedReadingInterval { // The coordinates on the polyline for the speed reading interval. repeated LatLng interval_coordinates = 1; // Describes the categorized current speed of road conditions. // Possible values are: // - "NORMAL": Road is flowing smoothly, no slowdown is detected. // - "SLOW": Slowdown detected, but no congestion formed. // - "TRAFFIC_JAM": Traffic jam detected. In this legacy field, heavy // traffic jams (dark red) are also reported as "TRAFFIC_JAM"; // "TRAFFIC_JAM_HEAVY" is never used. string speed = 2; } // Offset-based speed reading interval along the route. message SpeedReadingOffset { // The distance offset from the start of the route in meters for the start // of the interval (inclusive). int32 start_offset = 1; // The distance offset from the start of the route in meters for the end of // the interval (exclusive; equals the start_offset of the subsequent // interval). int32 end_offset = 2; // Describes the categorized current speed of traffic, aligned with the // colors in the Google Maps traffic layer. Possible values are: // - "NORMAL" (green): Traffic is flowing smoothly, no slowdown is detected. // - "SLOW" (yellow): Slowdown detected, but no traffic jam formed. // - "TRAFFIC_JAM" (red): Traffic jam detected. // - "TRAFFIC_JAM_HEAVY" (dark red): Heavy traffic jam detected (available // as of October 8, 2026). string speed = 3; } // Id for selected_route. string selected_route_id = 1; // User provided name for the route. string display_name = 2; // Legacy coordinate-based speed reading intervals. May stop being populated // on or after November 9, 2026. Use speed_reading_offsets instead. repeated SpeedReadingInterval speed_reading_intervals = 3; // Legacy travel time information. May stop being populated on or after // November 9, 2026. Use duration_in_seconds and static_duration_in_seconds // instead. TravelDuration travel_duration = 4; // Legacy timestamp when the road data was collected. May stop being populated // on or after November 9, 2026. Use retrieval_timestamp instead. Timestamp retrieval_time = 5; // Contains a geojson polyline representing the optimal route determined // based on user's input waypoints. string route_geometry = 6; // Road segment place IDs along the route. They follow topological order // and are always connected. repeated string road_segment_ids = 7; // Offset-based speed reading intervals representing traffic density across // the route; each interval is demarcated by the distance offset from the // start of the route. repeated SpeedReadingOffset speed_reading_offsets = 8; // The duration of travel through the route based on current traffic // conditions. float duration_in_seconds = 9; // The duration of travel through the route without taking traffic // conditions into consideration. float static_duration_in_seconds = 10; // The time the traffic data was collected, as an RFC 3339 UTC timestamp // string (for example, "2026-10-08T15:04:05+00:00"). string retrieval_timestamp = 11; }
以偏移量為準的朗讀速度間隔和欄位遷移
自 2026 年 10 月 8 日起,系統會在以偏移量為準的 speed_reading_offsets 欄位中提供速讀間隔,每個間隔會以路線起點的 start_offset (含) 和 end_offset (不含) (以公尺為單位) 劃分,並包含第四個速度類別 TRAFFIC_JAM_HEAVY。如要瞭解速度類別和間隔格式的詳細資料,請參閱「朗讀速度間隔」。
下表列出每個舊版 Pub/Sub 欄位 (可能在 2026 年 11 月 9 日當天或之後停止填入資料) 的替代欄位:
| 舊版欄位 | 取代欄位 | 附註 |
|---|---|---|
speed_reading_intervals |
speed_reading_offsets |
使用公尺偏移 (start_offset、end_offset) 而非折線座標,並新增 TRAFFIC_JAM_HEAVY 速度類別。 |
travel_duration.duration_in_seconds |
duration_in_seconds |
壓平至頂層 float 欄位。 |
travel_duration.static_duration_in_seconds |
static_duration_in_seconds |
壓平至頂層 float 欄位。 |
retrieval_time |
retrieval_timestamp |
格式為 RFC 3339 字串,BigQuery 訂閱項目會自動轉換為 TIMESTAMP。 |
使用 Pub/Sub 將路線資料串流至 BigQuery
您可以設定 Pub/Sub 訂閱項目,將道路資料直接串流至 BigQuery 資料表。這可確保資料儲存空間充足,並對提供的路線資訊進行強大的分析。設定這類訂閱項目之前,您需要在 BigQuery 專案中建立合適的資料集和資料表,以便寫入資料。
如需如何建立可將資料寫入 BigQuery 的 Pub/Sub 訂閱項目,請參閱「將資料串流至 BigQuery」一文。在 JSON 編碼的主題上建立 BigQuery 訂閱項目。設定訂閱項目時,請選取「使用表格結構定義」並啟用「捨棄不明欄位」,這樣一來,即使新增欄位,擷取管道也能繼續順利運作。如要儲存新欄位 (例如 speed_reading_offsets),請在表格中新增對應的資料欄。
BigQuery 資料表結構定義
發布至 Pub/Sub 主題的訊息 (也可以寫入 BigQuery 資料表) 會符合下列結構定義。建立目標 BigQuery 資料表時,請使用這個結構定義,確保相容性。
[ { "mode": "NULLABLE", "name": "selected_route_id", "type": "STRING", "description": "Id for selected_route." }, { "mode": "NULLABLE", "name": "display_name", "type": "STRING", "description": "User provided name for the route." }, { "fields": [ { "mode": "NULLABLE", "name": "speed", "type": "STRING", "description": "Describes the categorized current speed of traffic. Possible values are: \"NORMAL\": Traffic is flowing smoothly, no slowdown is detected. \"SLOW\": Slowdown detected, but no traffic jam formed. \"TRAFFIC_JAM\": Traffic jam detected (groups red and dark red segments; does not include \"TRAFFIC_JAM_HEAVY\")." }, { "fields": [ { "mode": "NULLABLE", "name": "latitude", "type": "NUMERIC" }, { "mode": "NULLABLE", "name": "longitude", "type": "NUMERIC" } ], "mode": "REPEATED", "name": "interval_coordinates", "type": "RECORD", "description": "The geometry for this interval" } ], "mode": "REPEATED", "name": "speed_reading_intervals", "type": "RECORD", "description": "Legacy coordinate-based speed reading intervals. May stop being populated on or after November 9, 2026. Use speed_reading_offsets instead." }, { "fields": [ { "mode": "NULLABLE", "name": "duration_in_seconds", "type": "FLOAT", "description": "The duration of travel through the route based on\ncurrent traffic conditions." }, { "mode": "NULLABLE", "name": "static_duration_in_seconds", "type": "FLOAT", "description": "The duration of travel through the route without\ntaking traffic conditions into consideration." } ], "mode": "NULLABLE", "name": "travel_duration", "type": "RECORD", "description": "Legacy travel time information. May stop being populated on or after November 9, 2026. Use top-level duration_in_seconds and static_duration_in_seconds instead." }, { "fields": [ { "mode": "NULLABLE", "name": "seconds", "type": "INTEGER", "description": "Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive." }, { "mode": "NULLABLE", "name": "nanos", "type": "INTEGER", "description": "Non-negative fractions of a second at nanosecond resolution. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be from 0 to 999,999,999 inclusive." } ], "mode": "NULLABLE", "name": "retrieval_time", "type": "RECORD", "description": "Legacy timestamp when the traffic data was collected. May stop being populated on or after November 9, 2026. Use retrieval_timestamp instead." }, { "mode": "NULLABLE", "name": "route_geometry", "type": "STRING", "description": "Contains a geojson polyline representing the optimal route determined based on user's input waypoints" }, { "mode": "REPEATED", "name": "road_segment_ids", "type": "STRING", "description": "Road segment place IDs along the route. They follow topological order and are always connected" }, { "fields": [ { "mode": "NULLABLE", "name": "start_offset", "type": "INTEGER", "description": "The distance offset from the start of the route in meters for the start of the interval (inclusive)." }, { "mode": "NULLABLE", "name": "end_offset", "type": "INTEGER", "description": "The distance offset from the start of the route in meters for the end of the interval (exclusive; equals the start_offset of the subsequent interval)." }, { "mode": "NULLABLE", "name": "speed", "type": "STRING", "description": "Describes the categorized current speed of traffic, aligned with the colors in the Google Maps traffic layer. Possible values are: \"NORMAL\" (green): Traffic is flowing smoothly, no slowdown is detected. \"SLOW\" (yellow): Slowdown detected, but no traffic jam formed. \"TRAFFIC_JAM\" (red): Traffic jam detected. \"TRAFFIC_JAM_HEAVY\" (dark red): Heavy traffic jam detected (available as of October 8, 2026)." } ], "mode": "REPEATED", "name": "speed_reading_offsets", "type": "RECORD", "description": "Offset-based speed reading intervals representing traffic density across the route; each interval is demarcated by the distance offset from the start of the route." }, { "mode": "NULLABLE", "name": "duration_in_seconds", "type": "FLOAT", "description": "The duration of travel through the route based on current traffic conditions." }, { "mode": "NULLABLE", "name": "static_duration_in_seconds", "type": "FLOAT", "description": "The duration of travel through the route without taking traffic conditions into consideration." }, { "mode": "NULLABLE", "name": "retrieval_timestamp", "type": "TIMESTAMP", "description": "The time the traffic data was collected." } ]