New pricing changes went into effect on July 16, 2018. For more information, check out the Guide for Existing Users.

Nearest Roads

The Roads API takes up to 100 independent coordinates, and returns the closest road segment for each point. The points passed do not need to be part of a continuous path.

If you are working with sequential GPS points, use Snap to Roads.

Requests

A request to nearest roads must be sent via HTTPS, and takes the following form:

https://roads.googleapis.com/v1/nearestRoads?parameters&key=YOUR_API_KEY

Parameter Usage

Required Parameters

  • points — A list of latitude/longitude pairs. Latitude and longitude values should be separated by commas. Coordinates should be separated by the pipe character: "|". For example: points=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796.
  • 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.

Responses

For each valid request, the Roads API will return a response in the format indicated within the request URL. The following elements may be present in a Snap to Roads response.

  • snappedPoints — An array of snapped points. Each point consists of the following fields:
    • location — Contains a latitude and longitude value.
    • originalIndex — An integer that indicates the corresponding value in the original request. Each point in the request maps to at most two segments in the response:
      • If there are no nearby roads, no segment is returned.
      • If the nearest road is one-way, one segment is returned.
      • If the nearest road is bidirectional, two segments are returned.
    • placeId — A unique identifier for a place. All place IDs returned by the Roads API correspond to road segments. Place IDs can be used with other Google APIs, including the Places SDK and the Maps JavaScript API. For example, if you need to get road names for the snapped points returned by the Roads API, you can pass the placeId to the Places SDK or the Geocoding API. Within the Roads API, you can pass the placeId in a speed limits request to determine the speed limit along that road segment.

Example Request

The following request returns a set of road segments based on the specified list of coordinates.

Request

https://roads.googleapis.com/v1/nearestRoads?points=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796&key=YOUR_API_KEY

Response

{
  "snappedPoints": [
    {
      "location": {
        "latitude": 60.170877918672588,
        "longitude": 24.942699821922421
      },
      "originalIndex": 0,
      "placeId": "ChIJNX9BrM0LkkYRIM-cQg265e8"
    },
    {
      "location": {
        "latitude": 60.170876898776406,
        "longitude": 24.942699912064771
      },
      "originalIndex": 1,
      "placeId": "ChIJNX9BrM0LkkYRIM-cQg265e8"
    },
    {
      "location": {
        "latitude": 60.170874902634374,
        "longitude": 24.942700088491474
      },
      "originalIndex": 2,
      "placeId": "ChIJNX9BrM0LkkYRIM-cQg265e8"
    }
  ]
}

Feedback geben zu...