Omówienie interfejsu Roads API
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Roads API to usługa, która akceptuje żądania HTTPS ze współrzędnymi geograficznymi (szerokością i długością geograficzną) co najmniej 1 punktu na mapie. Na podstawie tych punktów wyszukuje pobliskie segmenty dróg i zwraca identyfikator miejsca wraz z metadanymi, takimi jak najbliższy segment drogi i ograniczenia prędkości.
Dlaczego warto korzystać z Roads API
Za pomocą Roads API możesz uzyskać informacje o ograniczeniach prędkości, szacowanych czasach dotarcia do celu lub inne metadane dotyczące dróg. Dzięki tym metadanym dróg możesz wzbogacić swoje aplikacje do nawigacji o te funkcje:
- Połącz współrzędne geograficzne z drogą lub drogami.
- Znajdowanie najbliższej drogi dla zestawu współrzędnych
- Wyświetlanie ograniczeń prędkości na odcinkach dróg
Co możesz zrobić w Roads API
Za pomocą Roads API możesz przypisywać współrzędne GPS do geometrii drogi i określać ograniczenie prędkości na poszczególnych odcinkach.
- Przyciąganie do dróg Ta usługa zwraca najbardziej prawdopodobne drogi, po których poruszał się użytkownik, na podstawie podanego zestawu współrzędnych GPS. Możesz określić maksymalnie 100 punktów GPS zebranych na trasie. Opcjonalnie możesz też poprosić usługę o interpolację dodatkowych punktów, co spowoduje, że ścieżka będzie płynnie przebiegać wzdłuż geometrii drogi.
- Najbliższe drogi Ta usługa zwraca najbliższy odcinek drogi dla punktu GPS. Możesz określić maksymalnie 100 punktów GPS. Określone punkty nie muszą być częścią ciągłej ścieżki.
- Ograniczenia prędkości Ta usługa zwraca opublikowane ograniczenie prędkości na danym odcinku drogi. Usługa ograniczenia prędkości jest dostępna dla wszystkich klientów z licencją na śledzenie zasobów. W przypadku klientów korzystających z abonamentu premium na platformę Mapy Google, którzy przeszli na płatność za wykorzystanie, ta funkcja pozostaje aktywna.
Jak działa Roads API
Roads API korzysta z 3 punktów końcowych, które akceptują współrzędne geograficzne lub identyfikatory miejsc, aby dostarczać dane o drogach, odcinkach lub ograniczeniach prędkości.
Poniższy przykład pokazuje żądanie dotyczące najbliższych dróg na podstawie zestawu współrzędnych geograficznych:
https://roads.googleapis.com/v1/nearestRoads
?points=60.170880%2C24.942795%7C60.170879%2C24.942796%7C60.170877%2C24.942796
&key=YOUR_API_KEY
Zasoby
W tabeli poniżej znajdziesz podsumowanie zasobów dostępnych w ramach interfejsu Roads API oraz zwracanych przez nie danych.
Zasoby danych |
Zwrócone dane |
Format zwrotu |
Przyciągaj do dróg
|
Zwraca tablicę zawierającą maksymalnie 100 punktów GPS z trasy. Zawiera współrzędne długości i szerokości geograficznej dopasowane do dróg oraz identyfikatory miejsc. Szczegółowe informacje znajdziesz w sekcji Odpowiedzi w przewodniku Przyciąganie do dróg.
|
|
Najbliższe drogi
|
Tablica zawierająca maksymalnie 100 niezależnych współrzędnych geograficznych (szerokość i długość geograficzna) oraz identyfikatory miejsc najbliższej drogi dla każdego określonego punktu.
Punkty nie muszą być ciągłe. Szczegółowe informacje znajdziesz w sekcji Odpowiedzi w przewodniku Najbliższe drogi.
|
Ograniczenia prędkości
|
Tablica zawierająca maksymalnie 100 elementów metadanych drogi. Zawierają one ograniczenia prędkości i identyfikatory miejsc, a jednostki są podane w km/h lub milach na godzinę. Szczegółowe informacje znajdziesz w sekcji Odpowiedzi w przewodniku Ograniczenia prędkości.
|
Jak używać Roads API
1 |
Wypróbuj wersję demonstracyjną przyciągania do dróg |
Kliknij wersję demonstracyjną, aby utworzyć ślad i zobaczyć, jak punkt końcowy przyciągania do dróg zapewnia płynne dane. Zobacz demo w przewodniku Przyciąganie do dróg. Nie potrzebujesz klucza interfejsu API.
|
2 |
Konfiguracja |
Zacznij od skonfigurowania projektu Google Cloud i wykonaj kolejne instrukcje konfiguracji, a potem dowiedz się, jak używać klucza interfejsu API.
|
3 |
Wypróbuj prośbę o przyciągnięcie do dróg |
Skorzystaj z jednego z przykładów dotyczących przyciągania do dróg i wypróbuj ten, który jest odpowiedni w Twoim przypadku.
|
4 |
Wyświetlanie ograniczeń prędkości na trasie |
Używając tych samych danych ścieżki, które zostały podane w żądaniu przyciągania do dróg, wyślij zapytanie o ograniczenie prędkości. Zobacz przykładowe żądanie z użyciem ścieżki.
|
5 |
Dowiedz się, jak przetwarzać długie ścieżki |
Zapoznaj się z sekcjami Przetwarzanie długich ścieżek w przewodniku Zaawansowane koncepcje.
|
6 |
Wprowadź dane o drogach do własnej aplikacji! |
Zapoznaj się ze szczegółowym przykładem kodu z demonstracji dotyczącej przyciągania do drogi, aby zacząć wdrażać w swojej aplikacji funkcje związane z danymi o drogach.
|
Dostępne biblioteki klienta
Wywołaj ten interfejs API w wybranym języku za pomocą jednej z tych bibliotek klienta:
Klient Java, klient Python, klient Go i klient Node.js dla usług Map Google to biblioteki klientów obsługiwane przez społeczność, udostępniane na licencji Apache 2.0.
Możesz je pobrać z GitHuba, gdzie znajdziesz też instrukcje instalacji i przykładowy kod.
Co dalej?
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-31 UTC.
[null,null,["Ostatnia aktualizacja: 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)"]]