速度限制
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Roads API 针对特定路段返回公布的限速信息。如果路段的限速可变,则返回该路段的默认限速。
无法保证 Roads API 返回的车速限制数据的准确性。提供的限速数据并非实时数据,可能为估计值,也可能不准确、不完整或已过时。如需查看提供限速数据的区域,请参阅覆盖范围详情。
请求
使用 HTTPS 发送限速请求,格式如下:
https://roads.googleapis.com/v1/speedLimits?parameters&key=YOUR_API_KEY
参数用法
必需参数
path
或 placeId
参数。
path
- 最多包含 100 个纬度/经度对的列表,表示一条路径。纬度和经度值必须以英文逗号分隔。
纬度/经度对必须以竖线字符“|”分隔。当您提供 path
参数时,API 会先将路径贴合到车辆最有可能行驶的道路上(与 snapToRoads
请求的处理方式相同),然后确定相关路段的速度限制。如果您不希望 API 对路径进行贴合,则必须传递 placeId
参数,如下所述。以下示例展示了包含三对纬度/经度的 path
参数:path=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796
。
placeId
- 表示一个或多个路段的地点 ID。
确保每个地点 ID 都指向路段,而不是其他类型的地点。您可以在每个请求中传递最多 100 个地点 ID。该 API 不会对提供的地点 ID 执行道路贴合操作。响应包含请求中每个地点 ID 的速度限制。
您可以发送 snapToRoads
或 nearestRoads
请求来查找相关地点 ID,然后将这些 ID 作为输入提供给 speedLimits
请求。以下示例展示了包含两个地点 ID 的 placeId
参数:
placeId=ChIJX12duJAwGQ0Ra0d4Oi4jOGE&placeId=ChIJLQcticc0GQ0RoiNZJVa5GxU
key
- 您应用的 API 密钥。您的应用每次向 Roads API 发送请求时都必须通过在每个请求中添加 API 密钥来标识自己。了解如何获取密钥。
可选参数
units
- 是否以公里/小时或英里/小时为单位返回限速。可以设置为 KPH
或 MPH
。默认设置为 KPH
。
响应
speedLimits
响应中可能包含以下元素:
speedLimits
- 道路元数据的数组。每个元素都包含以下字段:
placeId
- 地点的唯一标识符。Roads API 返回的所有地点 ID 都将对应于路段。
speedLimit
- 相应路段的限速。
units
- 返回 KPH
或 MPH
。
snappedPoints
- 贴合点的数组。仅当请求包含 path
参数时,此数组才会存在。每个点都包含以下字段:
location
- 包含 latitude
和 longitude
值。
originalIndex
- 一个整数,用于指示原始请求中的相应值。请求中的每个值都应映射到响应中的贴靠值。这些值的索引从 0
开始,因此 originalIndex
为 4
的点将是传递给 path
参数的第 5 个纬度/经度的贴靠值。
placeId
- 地点的唯一标识符。Roads API 返回的所有地点 ID 都将对应于路段。
placeId
可在限速请求中传递,以确定相应路段的限速。
warning_message
- 包含用户可见警告的字符串。
使用路径的请求示例
此请求会获取路径中距离指定纬度/经度对最近的每个路段的限速信息,该路径会穿过葡萄牙里斯本的瓦斯科·达·伽马大桥。
请求
https://roads.googleapis.com/v1/speedLimits?path=38.75807927603043,-9.03741754643809|38.6896537,-9.1770515|41.1399289,-8.6094075&key=YOUR_API_KEY
答案
{
speedLimits:
[
{
placeId: "ChIJX12duJAwGQ0Ra0d4Oi4jOGE",
speedLimit: 105,
units: "KPH"
},
{
placeId: "ChIJLQcticc0GQ0RoiNZJVa5GxU",
speedLimit: 70,
units: "KPH"
},
{
placeId: "ChIJJ4vQRudkJA0RpednU70A-5M",
speedLimit: 55,
units: "KPH"
}
],
snappedPoints:
[
{
location:
{
latitude: 38.75807927603043,
longitude: -9.037417546438084
},
originalIndex: 0,
placeId: "ChIJX12duJAwGQ0Ra0d4Oi4jOGE"
},
{
location:
{
latitude: 38.689653701836896,
longitude: -9.177051486847693
},
originalIndex: 1,
placeId: "ChIJLQcticc0GQ0RoiNZJVa5GxU"
},
{
location:
{
latitude: 41.13993011767777,
longitude: -8.609400794783655
},
originalIndex: 2,
placeId: "ChIJJ4vQRudkJA0RpednU70A-5M"
}
],
warningMessage: "Input path is too sparse. You should provide a path where consecutive points are closer to each other. Refer to the 'path' parameter in Google Roads API documentation."
}
请注意上述响应中有关点稀疏性的警告消息。如果您要请求任意点处最近路段的限速,则必须使用从 nearestRoads
端点检索到的地点 ID 调用 speedLimits
。
使用地点 ID 的请求示例
您可以传递路段的地点 ID,而不是使用经纬度对。我们建议您使用 snapToRoads
或 nearestRoads
请求获取路段的地点 ID。传递地点 ID 时,API 会返回每个地点 ID 所代表的路段的限速信息。该 API 不会对提供的地点 ID 应用任何道路贴合。
以下示例请求了葡萄牙里斯本瓦斯科达伽马大桥上部分路段的限速。
请求
https://roads.googleapis.com/v1/speedLimits?placeId=ChIJX12duJAwGQ0Ra0d4Oi4jOGE&placeId=ChIJLQcticc0GQ0RoiNZJVa5GxU&placeId=ChIJJ4vQRudkJA0RpednU70A-5M&key=YOUR_API_KEY
答案
{
"speedLimits": [
{
placeId: "ChIJX12duJAwGQ0Ra0d4Oi4jOGE",
speedLimit: 105,
units: "KPH"
},
{
placeId: "ChIJLQcticc0GQ0RoiNZJVa5GxU",
speedLimit: 70,
units: "KPH"
},
{
placeId: "ChIJJ4vQRudkJA0RpednU70A-5M",
speedLimit: 55,
units: "KPH"
}
]
}
使用建议
为了尽量减少对速度限制服务的调用次数,我们建议每隔 5 到 15 分钟对资产位置进行采样(确切的值取决于资产的行驶速度)。如果资产固定不动,一个位置样本就够(无需多次调用)。
为了尽可能缩短总体延迟时间,我们建议您在累积一些数据后再调用速度限制服务,而不是每次收到移动资产位置时都调用 API。
为什么缺少部分/所有限速信息?
缺少 speedLimits
的最常见原因是请求了非路段地点的限速。
上述示例使用瓦斯科·达·伽马大桥来说明相关概念;该桥梁支持 E90 公路跨越特茹河。该桥梁本身的地点 ID 为 ChIJUzt97ZEwGQ0RM1JzQfqoDtU。上述响应中的第一个路段是 E90 公路的一部分,其地点 ID 为 ChIJX12duJAwGQ0Ra0d4Oi4jOGE。在示例请求中,如果您将道路地点 ID 替换为桥梁的地点 ID,则响应中的 speedLimits
数组中将只有两个限速,因为桥梁的地点 ID 不会引用单个路段。此外,如果所有地点 ID 都不对应于路段,则响应中不会包含任何限速信息。
使用地点 ID 发出限速请求时,请确保每个地点 ID 都指向路段,而不是其他类型的地点。最好使用 snapToRoads
或 nearestRoads
请求检索各个路段的地点 ID,这两种请求都可以通过一次调用返回多个地点 ID。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Roads API returns the posted speed limit for given road segments, but the accuracy of the data is not guaranteed and may not be real-time.\u003c/p\u003e\n"],["\u003cp\u003eYou can request speed limits by providing a path of latitude/longitude pairs or place IDs of road segments, using the \u003ccode\u003epath\u003c/code\u003e or \u003ccode\u003eplaceId\u003c/code\u003e parameters respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe response includes the speed limit, units (KPH or MPH), and may include snapped points if a path was provided.\u003c/p\u003e\n"],["\u003cp\u003eSpeed limit data might be missing if the requested place ID is not a road segment; use \u003ccode\u003esnapToRoads\u003c/code\u003e or \u003ccode\u003enearestRoads\u003c/code\u003e to obtain place IDs for road segments.\u003c/p\u003e\n"],["\u003cp\u003eTo optimize usage, sample asset locations at intervals and batch speed limit requests for reduced latency and API calls.\u003c/p\u003e\n"]]],["The Speed Limit service, available with an Asset Tracking license, returns posted speed limits for road segments via the Roads API. Requests, sent via HTTPS, require either a `path` (latitude/longitude pairs) or `placeId` of road segments. The API can snap paths to roads or directly use road segment place IDs. Optional parameters include `units` (KPH/MPH). Responses provide speed limit, units, and place ID. Accuracy isn't guaranteed. Optimal use includes sampling locations every 5-15 minutes, and batching requests. Ensure PlaceIds refer to road segments.\n"],null,["# Speed limits\n\n| **Notice:** The Speed Limit service is available to all customers with an [Asset\n| Tracking](https://cloud.google.com/maps-platform/asset-tracking) license. For [Google Maps Platform Premium Plan](/maps/premium) customers who transitioned to pay-as-you-go pricing, the Speed Limit feature remains active on projects with Asset Tracking capabilities (projects with a project ID in the format maps-asset-xxx).\n\nThe Roads API returns the posted speed limit for a given road\nsegment. In the case of road segments with variable speed limits, the default\nspeed limit for the segment is returned.\n\nThe accuracy of speed limit data returned by the Roads API\ncannot be guaranteed. The speed limit data provided is not real-time, and may be\nestimated, inaccurate, incomplete, or outdated. See [coverage details](/maps/coverage)\nto see the regions where speed limit data is available.\n\nRequests\n--------\n\nSend requests for speed limits using HTTPS, in the following form: \n\n```scdoc\nhttps://roads.googleapis.com/v1/speedLimits?parameters&key=YOUR_API_KEY\n```\n\n\u003cbr /\u003e\n\n### Parameter usage\n\n**Required parameters**\n\n- Either a `path` or a `placeId` parameter.\n - `path` --- A list of up to 100 latitude/longitude pairs representing a path. Latitude and longitude values must be separated by commas. Latitude/longitude pairs must be separated by the pipe character: \"\\|\". When you supply the `path` parameter, the API first snaps the path to the most likely road traveled by a vehicle (as it does for the [`snapToRoads`](/maps/documentation/roads/snap) request), then determines the speed limit for the relevant road segment. If you don't want the API to snap the path, you must pass a `placeId` parameter as explained below. The following example shows the `path` parameter with three latitude/longitude pairs: `path=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796`.\n - `placeId` --- The place ID(s) representing one or more road segments. Make sure each place ID refers to a road segment and not a different type of place. You can pass up to 100 place IDs with each request. The API does not perform road-snapping on the supplied place IDs. The response includes a speed limit for each place ID in the request. You can send a [`snapToRoads`](/maps/documentation/roads/snap) or [`nearestRoads`](/maps/documentation/roads/nearest) request to find the relevant place IDs then supply them as input to the `speedLimits` request. The following example shows the `placeId` parameter with two place IDs: `placeId=ChIJX12duJAwGQ0Ra0d4Oi4jOGE&placeId=ChIJLQcticc0GQ0RoiNZJVa5GxU`\n- `key` --- Your application's API key. Your application must identify itself every time it sends a request to the Roads API by including an API key with each request. Learn how to [get a key](/maps/documentation/roads/get-api-key).\n\n**Optional parameters**\n\n- `units` --- Whether to return speed limits in kilometers or miles per hour. This can be set to either `KPH` or `MPH`. Defaults to `KPH`.\n\nResponses\n---------\n\nThe following elements may be present in a `speedLimits` response:\n\n- `speedLimits` --- An array of road metadata. Each element consists of the following fields:\n - `placeId` --- A unique identifier for a place. All place IDs returned by the Roads API will correspond to road segments.\n - `speedLimit` --- The speed limit for that road segment.\n - `units` --- Returns either `KPH` or `MPH`.\n- `snappedPoints` --- an array of snapped points. This array is present only if the request contained a `path` parameter. Each point consists of the following fields:\n - `location` --- contains a `latitude` and `longitude` value.\n - `originalIndex` --- An integer that indicates the corresponding value in the original request. Each value in the request should map to a snapped value in the response. These values are indexed from `0`, so a point with an `originalIndex` of `4` will be the snapped value of the 5th latitude/longitude passed to the `path` parameter.\n - `placeId` --- A unique identifier for a place. All place IDs returned by the Roads API will correspond to road segments. The `placeId` can be passed in a speed limits request to determine the speed limit along that road segment.\n- `warning_message` --- A string containing a user-visible warning.\n\nExample request using a path\n----------------------------\n\nThis request gets the speed limit for each road segment nearest to the\nspecified latitude/longitude pairs in a path crossing the Vasco da Gama\nbridge in Lisbon, Portugal.\n\n**Request** \n\n```scdoc\nhttps://roads.googleapis.com/v1/speedLimits?path=38.75807927603043,-9.03741754643809|38.6896537,-9.1770515|41.1399289,-8.6094075&key=YOUR_API_KEY\n```\n\n**Response** \n\n```text\n{\n speedLimits:\n [\n {\n placeId: \"ChIJX12duJAwGQ0Ra0d4Oi4jOGE\",\n speedLimit: 105,\n units: \"KPH\"\n },\n {\n placeId: \"ChIJLQcticc0GQ0RoiNZJVa5GxU\",\n speedLimit: 70,\n units: \"KPH\"\n },\n {\n placeId: \"ChIJJ4vQRudkJA0RpednU70A-5M\",\n speedLimit: 55,\n units: \"KPH\"\n }\n ],\n snappedPoints:\n [\n {\n location:\n {\n latitude: 38.75807927603043,\n longitude: -9.037417546438084\n },\n originalIndex: 0,\n placeId: \"ChIJX12duJAwGQ0Ra0d4Oi4jOGE\"\n },\n {\n location:\n {\n latitude: 38.689653701836896,\n longitude: -9.177051486847693\n },\n originalIndex: 1,\n placeId: \"ChIJLQcticc0GQ0RoiNZJVa5GxU\"\n },\n {\n location:\n {\n latitude: 41.13993011767777,\n longitude: -8.609400794783655\n },\n originalIndex: 2,\n placeId: \"ChIJJ4vQRudkJA0RpednU70A-5M\"\n }\n ],\n warningMessage: \"Input path is too sparse. You should provide a path where consecutive points are closer to each other. Refer to the 'path' parameter in Google Roads API documentation.\"\n}\n```\n\nNotice the **warning message** for point sparsity in the above response. If you\nare requesting speed limits for the nearest road segments at arbitrary points,\nyou must call `speedLimits` with place IDs retrieved from the\n[`nearestRoads`](/maps/documentation/roads/nearest) endpoint instead.\n\nExample request using place IDs\n-------------------------------\n\nInstead of using latitude/longitude pairs, you can pass the place IDs of the\nroad segments. We recommend you obtain place IDs for road segments using\n`snapToRoads` or `nearestRoads` requests. When you pass place IDs, the API\nreturns the speed limit for the road segment represented by each place ID. The\nAPI does not apply any road-snapping to the place IDs supplied.\n\nThe following example requests the speed limits for some of the road segments\nthat cross the Vasco da Gama bridge in Lisbon, Portugal.\n\n**Request** \n\n```scdoc\nhttps://roads.googleapis.com/v1/speedLimits?placeId=ChIJX12duJAwGQ0Ra0d4Oi4jOGE&placeId=ChIJLQcticc0GQ0RoiNZJVa5GxU&placeId=ChIJJ4vQRudkJA0RpednU70A-5M&key=YOUR_API_KEY\n```\n\n**Response** \n\n```text\n{\n \"speedLimits\": [\n {\n placeId: \"ChIJX12duJAwGQ0Ra0d4Oi4jOGE\",\n speedLimit: 105,\n units: \"KPH\"\n },\n {\n placeId: \"ChIJLQcticc0GQ0RoiNZJVa5GxU\",\n speedLimit: 70,\n units: \"KPH\"\n },\n {\n placeId: \"ChIJJ4vQRudkJA0RpednU70A-5M\",\n speedLimit: 55,\n units: \"KPH\"\n }\n ]\n}\n```\n\nUsage recommendations\n---------------------\n\nTo minimize the volume of calls to the Speed Limit service, we recommend\nsampling the locations of your assets at 5 to 15 minute intervals (the exact\nvalue depends on the speed at which an asset is traveling). If an asset is\nstationary, a single location sample is sufficient (there is no need to make\nmultiple calls).\n\nTo minimize overall latency, we recommend calling the Speed Limit service\nonce you have accumulated some data, rather than calling the API every time the\nlocation of a mobile asset is received.\n\nWhy are some/all speed limits missing?\n--------------------------------------\n\nThe most common cause of missing `speedLimits` is requesting the speed limit\nof a place that is not a road segment.\n\nThe above example uses the Vasco da Gama bridge to illustrate concepts;\nthe bridge supports the road E90 crossing over the Rio Tejo. The bridge\nitself has a place ID of ChIJUzt97ZEwGQ0RM1JzQfqoDtU. The first road segment\nin the above response is part of the E90 road and has a place ID of\nChIJX12duJAwGQ0Ra0d4Oi4jOGE. In the example request, if you replace the road\nplace ID with the bridge's place ID, then in the response there will only be\ntwo speed limits in the `speedLimits` array because the bridge's place ID\ndoes not refer to an individual road segment. Furthermore, if none of the\nplace IDs are for road segments, then the response won't contain any\nspeed limits.\n\nWhen making speed limit requests using place IDs, make sure each place ID\nrefers to a road segment and not a different type of place. Place IDs for\nindividual road segments are best retrieved using `snapToRoads`\nor `nearestRoads` requests, either of which can return multiple place IDs from\na single call."]]