Dữ liệu đường bộ theo thời gian thực

Dữ liệu đường 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 và sự kiện cho các tuyến đường bạn chọn, hỗ trợ hoạt động giám sát động 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 các 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 độ đoạ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 về Thời lượng chuyến đi và Khoảng thời gian đọc tốc độ

Bạn sẽ được cung cấp các chủ đề Google Cloud Pub/Sub riêng biệt. Tạ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ẫu mã sau đây cho thấy định dạng của chủ đề bằng cá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 bằng cách 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 cho mình để nhận thông báo dữ liệu theo thời gian thực. Hãy xem bài viết Đă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 đồ Thời lượng chuyến đi và Khoảng thời gian đọc tốc độ

Mỗi thông báo dữ liệu theo thời gian thực kết hợp dữ liệu như:

  • Thông tin chi tiết về đường như travel_durationspeed_reading_intervals.
  • Giá trị nhận dạng tuyến đường như selected_route_iddisplay_name.

Mỗi thông báo được xuất bản tuân thủ đị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 {
  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;
  }
  // Represents the latitude and longitude of a coordinate
  // within speed reading interval.
  message LatLng {
    float latitude = 1;
    float longitude = 2;
  }
  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": Congestion detected.
    string speed = 2;
  }
  // Id for selected_route.
  string selected_route_id = 1;
  // User provided name for the route.
  string display_name = 2;
  // Intervals representing the road density across the route.
  repeated SpeedReadingInterval speed_reading_intervals = 3;
  // Travel time information.
  TravelDuration travel_duration = 4;
  // The time the road data was collected.
  Timestamp retrieval_time = 5;
  // Contains a geojson polyline representing the optimal route determined
  // based on user's input waypoints.
  string route_geometry = 6;
}

Truyền trực tuyến Dữ liệu tuyến đường sang 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 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à phân tích hiệu quả 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.

Hãy xem bài viết Truyền trực tuyến dữ liệu sang BigQuery để biết hướng dẫn chi tiết về cách tạo gói thuê bao Pub/Sub ghi vào BigQuery.

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 thủ giản đồ sau đây. 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."
      },
      {
        "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": "Intervals representing the traffic density across the route."
  },
  {
    "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": "Travel time information."
  },
  {
    "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": "The time the traffic data was collected."
  },
  {
    "mode": "NULLABLE",
    "name": "route_geometry",
    "type": "STRING",
    "description": "Contains a geojson polyline representing the optimal route determined based on user's input waypoints"
  }