实时道路数据可提供所选路线的最新路况和事件动态,支持动态监控和快速响应。此数据与 BigQuery 中定期收集的数据不同,适用于需要及时信息的场景。
这些数据会持续流式传输,包括:行程时长(表示路线上的行驶时间)和速度读取间隔(表示路段密度)。
如需访问实时道路数据,您的合同必须包含“实时运营”软件包。
创建 Cloud Pub/Sub 订阅
将项目设置为接收实时数据后,您的项目将可以使用专用的 Google Cloud Pub/Sub 主题。您可以在此 Pub/Sub 主题中找到所有已创建路线的实时数据。
以下代码示例展示了主题 网址 的格式。
projects/maps-platform-roads-management/topics/rmi-roadsinformation-PROJECT_NUMBER
您必须订阅提供给您的发布/订阅主题才能接收实时数据消息。有关如何订阅和使用 Cloud Pub/Sub 主题中的消息的快速概述,请参阅 订阅主题。
实时交通数据消息模式
每条实时数据消息都包含以下数据:
道路详情,例如 travel_duration 和 speed_reading_intervals。
路线标识符,例如 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 {
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;
}
使用 Pub/Sub 将路线数据流式传输到 BigQuery
您可以配置 Pub/Sub 订阅,将 road data 直接流式传输到 BigQuery 表中。这样可以实现强大的数据存储,并能够对提供的路线信息进行强大的分析。在设置此类订阅之前,您需要在 BigQuery 项目中创建一个合适的数据集和表来写入数据。
有关如何创建写入 BigQuery 的 Pub/Sub 订阅的详细说明,请参阅 将数据流式传输到 BigQuery。
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."
},
{
"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 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": "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"
}
