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 sá và các sự kiện trên tuyến đường bạn chọn, hỗ trợ việc 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 gian di chuyển, 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 Hoạt động theo thời gian thực.
Tạo gói thuê bao Pub/Sub cho khoảng thời gian di chuyển và khoảng thời gian đọc tốc độ
Bạn sẽ được cung cấp các chủ đề Google Cloud Pub/Sub chuyên biệt, 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 bạn đã tạo.
Mã mẫu sau đây cho thấy định dạng của chủ đề sử dụng phương thức 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 sử dụng phương thức mã hoá JSON (có hậu tố -json). Bạn phải đăng ký chủ đề Pub/Sub được cung cấp để nhận thông báo dữ liệu theo thời gian thực. Hãy xem phần Đăng ký một chủ đề để biết thông tin tổng quan nhanh về cách đăng ký và sử dụng thông báo từ một chủ đề Cloud Pub/Sub.
Giản đồ về khoảng thời gian đọc tốc độ và thời gian di chuyển
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 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),retrieval_timestampvàhas_road_closure. - 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 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. Omitted when has_road_closure is true. repeated SpeedReadingOffset speed_reading_offsets = 8; // The duration of travel through the route based on current traffic // conditions. Omitted when has_road_closure is true. 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; // Whether there is a full road closure on the route. When true, // duration_in_seconds and speed_reading_offsets are omitted because the // route is impassable. Omitted when road closure information is undetermined. bool has_road_closure = 12; }
Khoảng thời gian đọc tốc độ dựa trên độ lệch và 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 độ đượ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 và bao gồm cả 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 tốc độ.
Bảng sau đây liên kết từng trường Pub/Sub cũ (có thể ngừng được điền sẵn từ 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 theo mét (start_offset, end_offset) thay vì toạ độ hình nhiều đường 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, chuỗi này được gói thuê bao BigQuery tự động chuyển đổi thành TIMESTAMP. |
Truyền dữ liệu tuyến đường đến BigQuery bằng Pub/Sub
Bạn có thể định cấu hình gói thuê bao Pub/Sub để truyền trực tuyến dữ liệu đường bộ trực tiếp vào bảng BigQuery. Điều này cho phép lưu trữ dữ liệu mạnh mẽ và cho phép phân tích mạnh mẽ thông tin tuyến đường được cung cấp. Trước khi thiết lập loại gó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 gói thuê bao Pub/Sub ghi vào BigQuery, hãy xem bài viết Truyền dữ liệu trực tuyến đến BigQuery.
Tạo gói thuê bao BigQuery trên chủ đề được mã hoá 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 Bỏ qua các trường
không xác định để quy trình nhập dữ liệu tiếp tục chạy mượt mà 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ũng có thể được ghi vào bảng BigQuery) tuân thủ giản đồ sau. Bạn nên sử dụng giản đồ này khi tạo bảng BigQuery đích để đả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. Omitted when has_road_closure is true." }, { "mode": "NULLABLE", "name": "duration_in_seconds", "type": "FLOAT", "description": "The duration of travel through the route based on current traffic conditions. Omitted when has_road_closure is true." }, { "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." }, { "mode": "NULLABLE", "name": "has_road_closure", "type": "BOOLEAN", "description": "Whether there is a full road closure on the route. When true, duration_in_seconds and speed_reading_offsets are omitted because the route is impassable. A NULL value indicates that road closure information is undetermined." } ]