Tổng quan về API Đường
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Roads API là một dịch vụ chấp nhận các yêu cầu HTTPS có toạ độ vĩ độ/kinh độ cho một hoặc nhiều điểm trên bản đồ. API này sử dụng các điểm này để tìm các đoạn đường lân cận và trả về một Mã địa điểm cùng với siêu dữ liệu, chẳng hạn như đoạn đường gần nhất và giới hạn tốc độ.
Lý do nên sử dụng Roads API
Với Roads API, bạn có thể nhận được thông tin về giới hạn tốc độ, thời gian đến dự kiến hoặc siêu dữ liệu khác về đường. Với siêu dữ liệu đường này, bạn có thể cải thiện các ứng dụng lái xe của mình bằng các chức năng sau:
- Kết nối toạ độ vĩ độ/kinh độ với một hoặc nhiều con đường.
- Tìm con đường gần nhất cho một tập hợp toạ độ
- Xem giới hạn tốc độ cho các đoạn đường
Những việc bạn có thể làm với Roads API
Với Roads API, bạn có thể liên kết toạ độ GPS với hình học của đường và xác định giới hạn tốc độ dọc theo các đoạn đường.
- Căn chỉnh theo đường Dịch vụ này trả về những con đường có khả năng được đi qua nhất dựa trên bộ toạ độ GPS được cung cấp. Bạn có thể chỉ định tối đa 100 điểm GPS được thu thập dọc theo một tuyến đường. Nếu muốn, bạn cũng có thể yêu cầu dịch vụ nội suy các điểm bổ sung, dẫn đến một đường dẫn theo sát hình học của đường một cách mượt mà.
- Nearest Roads Dịch vụ này trả về đoạn đường gần nhất cho một điểm GPS. Bạn có thể chỉ định tối đa 100 điểm GPS. Các điểm mà bạn chỉ định không cần phải nằm trong một đường dẫn liên tục.
- Giới hạn tốc độ Dịch vụ này trả về giới hạn tốc độ được đăng cho một đoạn đường. Dịch vụ Giới hạn tốc độ được cung cấp cho tất cả khách hàng có giấy phép Theo dõi tài sản. Đối với những khách hàng sử dụng gói Google Maps Platform Premium và đã chuyển sang mô hình định giá trả theo mức sử dụng, tính năng này vẫn hoạt động.
Cách thức hoạt động của Roads API
Roads API sử dụng 3 điểm cuối chấp nhận toạ độ vĩ độ/kinh độ hoặc mã địa điểm để cung cấp dữ liệu về đường đi, đoạn đường hoặc giới hạn tốc độ.
Ví dụ sau đây cho thấy một yêu cầu về những con đường gần nhất dựa trên một tập hợp toạ độ vĩ độ/kinh độ:
https://roads.googleapis.com/v1/nearestRoads
?points=60.170880%2C24.942795%7C60.170879%2C24.942796%7C60.170877%2C24.942796
&key=YOUR_API_KEY
Tài nguyên
Bảng sau đây tóm tắt các tài nguyên có sẵn thông qua Roads API cùng với dữ liệu mà tài nguyên đó trả về.
Tài nguyên dữ liệu |
Dữ liệu được trả về |
Định dạng trả về |
Canh chỉnh theo đường
|
Trả về một mảng gồm tối đa 100 điểm GPS từ một tuyến đường. Bao gồm toạ độ kinh độ/vĩ độ được gắn vào đường cùng với mã địa điểm. Xem thông tin chi tiết trong phần
Phản hồi
trong hướng dẫn Căn chỉnh theo đường.
|
|
Đường gần nhất
|
Một mảng gồm tối đa 100 toạ độ vĩ độ/kinh độ độc lập cùng với mã địa điểm cho con đường gần nhất của từng điểm được chỉ định.
Các điểm không cần phải liên tục. Xem thông tin chi tiết trong phần Phản hồi trong hướng dẫn về Đường gần nhất.
|
Giới hạn tốc độ
|
Một mảng có tối đa 100 phần tử siêu dữ liệu đường. Các đối tượng này chứa giới hạn tốc độ và mã địa điểm, với đơn vị là km/giờ hoặc dặm/giờ. Xem thông tin chi tiết trong phần Phản hồi trong hướng dẫn về Giới hạn tốc độ.
|
Cách sử dụng Roads API
1 |
Dùng thử bản minh hoạ tính năng khớp với đường |
Nhấp vào bản minh hoạ để tạo một tuyến đường và xem cách điểm cuối snap to roads cung cấp dữ liệu mượt mà. Xem Bản minh hoạ trong hướng dẫn Căn chỉnh theo đường. Bạn không cần khoá API.
|
2 |
Thiết lập |
Bắt đầu bằng cách Thiết lập dự án Google Cloud và hoàn tất hướng dẫn thiết lập tiếp theo, sau đó tìm hiểu cách sử dụng khoá API.
|
3 |
Thử yêu cầu gắn vào đường |
Sử dụng một trong các ví dụ về tính năng khớp với đường và thử một ví dụ phù hợp với trường hợp sử dụng của bạn.
|
4 |
Xem giới hạn tốc độ cho tuyến đường của bạn |
Sử dụng cùng dữ liệu đường đi mà bạn đã cung cấp cho yêu cầu gắn kết với đường, hãy đưa ra một truy vấn giới hạn tốc độ. Xem Ví dụ về yêu cầu sử dụng đường dẫn.
|
5 |
Tìm hiểu cách xử lý các đường dẫn dài |
Làm theo các phần về Xử lý đường dẫn dài trong hướng dẫn Các khái niệm nâng cao.
|
6 |
Tích hợp dữ liệu đường vào ứng dụng của riêng bạn! |
Hãy xem ví dụ chi tiết về mã trong bản minh hoạ đường được điều chỉnh để bắt đầu xây dựng chức năng dữ liệu đường vào ứng dụng của riêng bạn.
|
Các thư viện ứng dụng hiện có
Gọi API này bằng ngôn ngữ bạn chọn thông qua một trong các thư viện ứng dụng sau:
Ứng dụng Java, ứng dụng Python, ứng dụng Go và ứng dụng Node.js cho Dịch vụ Google Maps là các thư viện ứng dụng được cộng đồng hỗ trợ, có nguồn mở theo Giấy phép Apache 2.0.
Bạn có thể tải các tệp này xuống từ GitHub, nơi bạn cũng có thể tìm thấy hướng dẫn cài đặt và mã mẫu.
Bước tiếp theo
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\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)"]]