Dữ liệu đường bộ theo thời gian thực cung cấp thông tin cập nhật mới nhất về tình trạng đường bộ và các sự kiện cho tuyến đường bạn chọn, hỗ trợ hoạt động giám sát linh hoạt và ứng phó nhanh chóng. Dữ liệu này khác với dữ liệu được thu thập định kỳ có trong BigQuery và phù hợp với những trường hợp cần thông tin kịp thời.
Dữ liệu này được truyền trực tuyến liên tục và bao gồm thời lượng chuyến đi (cho biết thời gian di chuyển trên một tuyến đường) và khoảng thời gian đọc tốc độ (cho biết mật độ giao thông dọc theo tuyến đường).
Để truy cập vào dữ liệu đường theo thời gian thực, hợp đồng của bạn phải bao gồm gói Vận hành theo thời gian thực.
Tạo gói thuê bao Pub/Sub về Khoảng thời gian di chuyển và Khoảng thời gian đọc tốc độ
Chúng tôi sẽ cung cấp cho bạn các chủ đề Google Cloud Pub/Sub chuyên dụng. Đây là nơi bạn có thể đăng ký nhận dữ liệu theo thời gian thực cho tất cả các tuyến đường mà bạn đã tạo.
Mẫu mã sau đây cho thấy định dạng của chủ đề bằng cách sử dụng mã hoá nhị phân:
projects/maps-platform-roads-management/topics/rmi-roadsinformation-PROJECT_NUMBER
Chúng tôi cũng cung cấp một chủ đề khác bằng cách sử dụng mã hoá JSON (có hậu tố -json). Bạn phải đăng ký chủ đề Pub/Sub được cung cấp cho bạn để nhận thông báo dữ liệu theo thời gian thực. Hãy xem phần Đăng ký theo dõi một chủ đề để biết thông tin tổng quan nhanh về cách đăng ký theo dõi và sử dụng thông báo từ một chủ đề Cloud Pub/Sub.
Giản đồ Thời lượng di chuyển và Khoảng thời gian đọc nhanh
Mỗi thông báo dữ liệu theo thời gian thực đều kết hợp các dữ liệu như:
- Thông tin chi tiết về đường, chẳng hạn như
duration_in_seconds,static_duration_in_seconds,speed_reading_offsets(khoảng thời gian đọc tốc độ dựa trên độ lệch) vàretrieval_timestamp. - Giá trị nhận dạng tuyến đường như
selected_route_idvàdisplay_name.
Mỗi thông báo được xuất bản tuân theo định dạng Protobuf sau đây.
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; }
Khoảng thời gian đọc tốc độ dựa trên độ lệch và quá trình di chuyển trường
Kể từ ngày 8 tháng 10 năm 2026, các khoảng thời gian đọc tốc độ sẽ được cung cấp trong trường speed_reading_offsets dựa trên độ lệch, trong đó mỗi khoảng thời gian được phân định bằng start_offset (bao gồm) và end_offset (không bao gồm) tính bằng mét từ điểm bắt đầu của tuyến đường, đồng thời bao gồm danh mục tốc độ thứ tư TRAFFIC_JAM_HEAVY. Để biết thông tin chi tiết về các danh mục tốc độ và định dạng khoảng thời gian, hãy xem phần Khoảng thời gian đọc nhanh.
Bảng sau đây liên kết từng trường Pub/Sub cũ (có thể ngừng được điền sẵn vào hoặc sau ngày 9 tháng 11 năm 2026) với trường thay thế:
| Trường cũ | Trường thay thế | Ghi chú |
|---|---|---|
speed_reading_intervals |
speed_reading_offsets |
Sử dụng độ lệch của đồng hồ đo (start_offset, end_offset) thay vì toạ độ đường nhiều đoạn và thêm danh mục tốc độ TRAFFIC_JAM_HEAVY. |
travel_duration.duration_in_seconds |
duration_in_seconds |
Được làm phẳng thành trường float cấp cao nhất. |
travel_duration.static_duration_in_seconds |
static_duration_in_seconds |
Được làm phẳng thành trường float cấp cao nhất. |
retrieval_time |
retrieval_timestamp |
Được định dạng dưới dạng chuỗi RFC 3339 mà các gói thuê bao BigQuery tự động chuyển đổi thành TIMESTAMP. |
Truyền trực tuyến dữ liệu tuyến đường đến BigQuery bằng Pub/Sub
Bạn có thể định cấu hình một thuê bao Pub/Sub để truyền trực tiếp dữ liệu đường vào một bảng BigQuery. Điều này giúp bạn lưu trữ dữ liệu một cách mạnh mẽ và cho phép phân tích hiệu quả thông tin về tuyến đường được cung cấp. Trước khi thiết lập loại thuê bao này, bạn cần tạo một tập dữ liệu và bảng phù hợp trong dự án BigQuery để ghi dữ liệu vào.
Để biết hướng dẫn chi tiết về cách tạo một thuê bao Pub/Sub ghi vào BigQuery, hãy xem bài viết Truyền trực tuyến dữ liệu đến BigQuery.
Tạo gói thuê bao BigQuery trên chủ đề được mã hoá bằng JSON. Khi định cấu hình gói thuê bao, hãy chọn Sử dụng giản đồ bảng và bật Xoá các trường không xác định để quy trình tiếp nhận của bạn tiếp tục chạy trơn tru khi các trường mới được thêm vào. Để lưu trữ các trường mới, chẳng hạn như speed_reading_offsets, hãy thêm các cột tương ứng vào bảng.
Giản đồ bảng BigQuery
Các thông báo được xuất bản lên chủ đề Pub/Sub của bạn (cũng có thể được ghi vào bảng BigQuery) tuân theo giản đồ sau. Bạn nên sử dụng giản đồ này khi tạo bảng BigQuery mục tiêu để đảm bảo khả năng tương thích.
[ { "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." } ]