ข้อมูลถนนแบบเรียลไทม์

ข้อมูลถนนแบบเรียลไทม์จะให้ข้อมูลอัปเดตล่าสุดเกี่ยวกับสภาพท้องถนนและเหตุการณ์ต่างๆ ในเส้นทางที่คุณเลือก ซึ่งรองรับการตรวจสอบแบบไดนามิกและการตอบสนองอย่างรวดเร็ว ข้อมูลนี้แตกต่างจากข้อมูลที่รวบรวมเป็นระยะๆ ซึ่งมีอยู่ใน 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
  • ตัวระบุเส้นทาง เช่น 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;
}

ช่วงการอ่านความเร็วที่อิงตามออฟเซ็ตและการย้ายข้อมูลฟิลด์

ตั้งแต่วันที่ 8 ตุลาคม 2026 เป็นต้นไป ระบบจะระบุช่วงการอ่านความเร็วในฟิลด์อิงตามออฟเซ็ต speed_reading_offsets โดยแต่ละช่วงจะมีการกำหนดขอบเขตด้วย start_offset (รวม) และ end_offset (ไม่รวม) ในหน่วยเมตรจากจุดเริ่มต้น ของเส้นทาง และรวมถึงหมวดหมู่ความเร็วที่ 4 TRAFFIC_JAM_HEAVY ดูรายละเอียดเกี่ยวกับหมวดหมู่ความเร็วและรูปแบบช่วงได้ที่ช่วงการอ่านความเร็ว

ตารางต่อไปนี้จะแมปฟิลด์ Pub/Sub แบบเดิมแต่ละฟิลด์ (ซึ่งอาจหยุดป้อนข้อมูลในวันที่ 9 พฤศจิกายน 2026 หรือหลังจากนั้น) กับฟิลด์ที่ใช้แทน

ฟิลด์เดิม ฟิลด์แทนที่ หมายเหตุ
speed_reading_intervals speed_reading_offsets ใช้การชดเชยมิเตอร์ (start_offset, end_offset) แทนพิกัด Polyline และเพิ่มหมวดหมู่ความเร็ว 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 โดยอัตโนมัติ

สตรีมข้อมูลเส้นทางไปยัง BigQuery โดยใช้ Pub/Sub

คุณสามารถกำหนดค่าการสมัครใช้บริการ Pub/Sub เพื่อสตรีมข้อมูลถนนไปยังตาราง BigQuery ได้โดยตรง ซึ่งช่วยให้จัดเก็บข้อมูลได้อย่างมีประสิทธิภาพและช่วยให้วิเคราะห์ข้อมูลเส้นทางที่ระบุได้อย่างมีประสิทธิภาพ ก่อนตั้งค่าการสมัครใช้บริการประเภทนี้ คุณต้องสร้างชุดข้อมูลและตารางที่เหมาะสมในโปรเจ็กต์ BigQuery เพื่อเขียนข้อมูล

ดูวิธีการโดยละเอียดในการสร้างการสมัครใช้บริการ Pub/Sub ที่เขียน ไปยัง BigQuery ได้ที่ การสตรีมข้อมูลไปยัง BigQuery สร้างการสมัครใช้บริการ BigQuery ในหัวข้อที่เข้ารหัส JSON เมื่อกำหนดค่าการสมัครใช้บริการ ให้เลือกใช้สคีมาตารางและเปิดใช้ทิ้งฟิลด์ที่ไม่รู้จักเพื่อให้ไปป์ไลน์การนำเข้าทำงานได้อย่างราบรื่นต่อไปเมื่อมีการเพิ่มฟิลด์ใหม่ หากต้องการจัดเก็บฟิลด์ใหม่ เช่น 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."
  }
]