Roads API 概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Roads API 是一项服务,可接受包含地图上一个或多个点的纬度/经度坐标的 HTTPS 请求。它会使用这些点来查找附近的道路路段,并返回地点 ID 以及元数据(例如最近的道路路段和限速)。
为何使用 Roads API
借助 Roads API,您可以获取限速、预计到达时间或其他道路元数据。借助这些道路元数据,您可以增强驾驶应用的功能,使其具备以下能力:
- 将纬度/经度坐标与一条或多条道路相关联。
- 查找一组坐标对应的最近道路
- 获取路段的限速信息
Roads API 的用途
借助 Roads API,您可以将 GPS 坐标映射到道路的几何形状,并确定道路路段的速度限制。
- 贴合道路:此服务会根据提供的一组 GPS 坐标返回最有可能行驶的道路。您最多可以指定沿路线收集的 100 个 GPS 点。您还可以选择请求服务插值其他点,从而生成一条平滑贴合道路几何形状的路径。
- 最近的道路:此服务会返回 GPS 点附近的路段。您最多可以指定 100 个 GPS 点。您指定的点不必是连续路径的一部分。
- 限速 此服务会针对路段返回公布的限速信息。所有拥有资产跟踪许可的客户都可以使用“限速”服务。对于已改用随用随付定价的 Google Maps Platform 高级计划客户,此功能仍处于有效状态。
Roads API 的运作方式
Roads API 使用三个端点,这些端点接受纬度/经度坐标或地点 ID,以提供道路路径、路段或限速数据。以下示例展示了基于一组纬度/经度坐标请求最近道路的示例:
https://roads.googleapis.com/v1/nearestRoads
?points=60.170880%2C24.942795%7C60.170879%2C24.942796%7C60.170877%2C24.942796
&key=YOUR_API_KEY
资源
下表总结了通过 Roads API 获得的资源及其返回的数据。
数据资源 |
返回的数据 |
返回格式 |
沿实际道路
|
返回路线中最多 100 个 GPS 点的数组。包括贴合道路的经度/纬度坐标以及地点 ID。如需了解详情,请参阅贴合道路指南中的响应。
|
|
最近的道路
|
一个数组,包含多达 100 个独立的纬度/经度坐标,以及每个指定点最近道路的地点 ID。
点无需连续。如需了解详情,请参阅最近的道路指南中的响应。
|
速度限制
|
一个包含最多 100 个道路元数据元素的数组。这些文件包含限速和地点 ID,单位为 KPH 或 MPH。如需了解详情,请参阅限速指南中的回答。
|
如何使用 Roads API
1 |
试用贴合到道路演示 |
点击演示,创建轨迹,并查看贴合道路端点如何提供平滑的数据。请参阅贴合到道路指南中的演示。您无需 API 密钥。
|
2 |
开始设置 |
首先设置您的 Google Cloud 项目,然后完成后续的设置说明,接着了解如何使用 API 密钥。
|
3 |
尝试贴合到道路请求 |
使用道路贴合示例,并尝试一个与您的使用情形相关的示例。
|
4 |
获取道路路线的速度限制 |
使用您为贴合道路请求提供的相同路径数据,发出限速查询。请参阅使用路径的示例请求。
|
5 |
了解如何处理长路径 |
请参阅高级概念指南中有关处理长路径的部分。
|
6 |
将道路数据整合到您自己的应用中! |
请参阅道路贴合演示中的详细代码示例,开始在自己的应用中构建道路数据功能。
|
可用的客户端库
通过以下客户端库之一,以您选择的语言调用此 API:
适用于 Google 地图服务的 Java 客户端、Python 客户端、Go 客户端和 Node.js 客户端是由社区提供支持的客户端库,并且根据 Apache 2.0 许可开放源代码。您可以从 GitHub 下载这些客户端库,还可以在其中找到安装说明和示例代码。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Roads API enhances maps applications by connecting coordinates with roads, finding nearby roads, and providing speed limit data.\u003c/p\u003e\n"],["\u003cp\u003eIt offers three core functionalities: snapping GPS points to roads, identifying nearest roads, and retrieving speed limits.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can leverage client libraries for Java, Python, Go, and Node.js to integrate the Roads API.\u003c/p\u003e\n"],["\u003cp\u003eThe API accepts latitude/longitude coordinates and returns data like Place IDs, road segments, and speed limits in JSON format.\u003c/p\u003e\n"],["\u003cp\u003eYou can get started by exploring the documentation, trying the demo, setting up a Google Cloud project, and experimenting with code examples.\u003c/p\u003e\n"]]],["The Roads API processes HTTPS requests with latitude/longitude coordinates to identify nearby road segments. It offers three main services: Snap to Roads, which maps up to 100 GPS points to road geometry; Nearest Roads, which identifies the closest road segment for up to 100 independent GPS points; and Speed Limits, which returns posted speed limits and place IDs for road segments. Users can integrate these functionalities using client libraries or by making direct requests with an API key.\n"],null,["# Roads API overview\n\nThe Roads API is a service that accepts HTTPS requests with latitude/longitude coordinates for one or more points on a map. It uses these points to find nearby road segments and returns a Place ID along with metadata such as the nearest road segment and speed limits.\n\nWhy use the Roads API\n---------------------\n\nWith the Roads API, you can get speed limits, estimated\narrival times, or other road metadata. With this road\nmetadata, you can enhance your driving apps with the follow capabilities:\n\n- Connect latitude/longitude coordinates with a road or roads.\n- Find the nearest road for a set of coordinates\n- Get speed limits for road segments\n\nWhat you can do with the Roads API\n----------------------------------\n\nWith the Roads API, you can map GPS coordinates to the\ngeometry of the road, and determine the speed limit along road\nsegments.\n\n- **[Snap to Roads](/maps/documentation/roads/snap)** This service returns the most likely roads traveled based on the provided set of GPS coordinates. You can specify up to 100 GPS points collected along a route. Optionally, you can also request that the service interpolates additional points, resulting in a path that smoothly follows the geometry of the road.\n- **[Nearest Roads](/maps/documentation/roads/nearest)** This service returns the nearest road segment for a GPS point. You can specify up to 100 GPS points. The points you specify don't need to be part of a continuous path.\n- **[Speed limits](/maps/documentation/roads/speed-limits)** This service returns the posted speed limit for a road segment. The Speed Limit service is available to all customers with an Asset Tracking license. For [Google Maps Platform Premium Plan](/maps/premium) customers who transitioned to pay-as-you-go pricing, the feature remains active.\n\nHow the Roads API works\n-----------------------\n\nThe Roads API uses three endpoints which accept latitude/longitude\ncoordinates or place IDs to provide road paths, segments, or speed limit data.\nThe following example shows a request for nearest roads based on a set\nof latitude/longitude coordinates: \n\n```scdoc\nhttps://roads.googleapis.com/v1/nearestRoads\n ?points=60.170880%2C24.942795%7C60.170879%2C24.942796%7C60.170877%2C24.942796\n &key=YOUR_API_KEY\n```\n\n### Resources\n\nThe following table summarizes the resources available through the\nRoads API along with the data it returns.\n\n\u003cbr /\u003e\n\n| Data resources | Data returned | Return format |\n|------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|\n| **[Snap to roads](/maps/documentation/roads/snap)** | Returns an array of up to 100 GPS points from a route. Includes road-snapped longitude/latitude coordinates along with place IDs. See details in [Responses](/maps/documentation/roads/snap#responses) in the Snap to roads guide. | - JSON |\n| **[Nearest roads](/maps/documentation/roads/nearest)** | An array of up to 100 independent latitude/longitude coordinates along with place IDs for the nearest road for each specified point. Points do not need to be continuous. See details in [Responses](/maps/documentation/roads/nearest#responses) in the Nearest roads guide. | - JSON |\n| **[Speed limits](/maps/documentation/roads/speed-limits)** | An array of up to 100 road metadata elements. These contain speed limits and place IDs, with units either in KPH or MPH. See details in [Responses](/maps/documentation/roads/nearest#responses) in the Speed limits guide. | - JSON |\n\n\u003cbr /\u003e\n\nHow to use the Roads API\n------------------------\n\n|---|----------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 1 | **Try the snap to roads demo** | Click the demo to create a track and see how the snap to roads endpoint provides smooth data. See [Demo](/maps/documentation/roads/snap#demo) in the **Snap to roads** guide. You don't need an API key. |\n| 2 | **Get set up** | Start with [Set up your Google Cloud project](/maps/documentation/roads/cloud-setup) and complete the setup instructions that follow and then learn [how to use your API key](/maps/documentation/roads/get-api-key). |\n| 3 | **Try a snap to roads request** | [Use one of the snap to roads examples](/maps/documentation/roads/snap#examples) and try one relevant to your use case. |\n| 4 | **Get speed limits for your road path** | Using the same path data you provided for your snap to roads request, issue a speed limit query. See the [Example request using a path](/maps/documentation/roads/speed-limits#example_request_using_a_path). |\n| 5 | **Learn how to process long paths** | Follow the sections on [Processing long paths](/maps/documentation/roads/advanced#processing_long_paths) in the **Advanced concepts** guide. |\n| 6 | **Incorporate road data into your own app!** | See the [detailed code example](/maps/documentation/roads/snap#javascript-+-html) from the road snapped demo to start building road data functionality into your own app. |\n\n### Available client libraries\n\nCall this API in the language of\nyour choice through one of the following client libraries:\n\n- [Java\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-java)\n- [Python\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-python)\n- [Go Client\n for Google Maps Services](https://github.com/googlemaps/google-maps-services-go)\n- [Node.js\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-js)\n\nThe Java Client, Python Client, Go Client and Node.js Client for Google Maps\nServices are community-supported client libraries, open sourced under the\n[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).\nDownload them from GitHub, where you can also find installation instructions and sample code.\n\nWhat's next\n-----------\n\n- **Try out the Roads API** : Go to [Roads Inspector](/maps/documentation/roads/inspector)\n- **Learn how to make Roads API requests** : Go to the service you're interested in:\n - [Snap to roads](/maps/documentation/roads/snap)\n - [Nearest roads](/maps/documentation/roads/nearest)\n - [Speed limits](/maps/documentation/roads/speed-limits)\n- **Understand Advanced Concepts** : Go to [Advanced Concepts](/maps/documentation/roads/advanced)\n- **Follow best practices** : Go to [Web Services Best Practices](/maps/documentation/roads/web-service-best-practices)"]]