Routes Preferred API is currently available only to select customers.
Contact sales to learn more.
Request Traffic Information on the Polyline
Stay organized with collections
Save and categorize content based on your preferences.
The Routes Preferred API offers the possibility of requesting information about traffic conditions
along the polyline. Traffic conditions are expressed in terms of speed categories (NORMAL, SLOW, TRAFFIC_JAM)
applicable on a given interval of the response polyline. The intervals are defined by the indexes of their starting (inclusive) and ending
(exclusive) polyline points.
Example Request
Traffic aware polyline is available for both route level and leg level.
At the route level, the traffic speed information is provided as
SpeedReadingIntervals
under the RouteTravelAdvisory response field.
In order to receive traffic information alongside the
polyline of the route, include both polyline
and speedReadingIntervals
in the response field mask.
If the field mask contains routes.legs.travelAdvisory.speedReadingIntervals
, then the response will contain the leg level traffic data under
RouteLegTravelAdvisory.
X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline,routes.travelAdvisory.speedReadingIntervals,routes.legs.polyline.encodedPolyline,routes.legs.travelAdvisory.speedReadingIntervals
Visit "Choose Fields to Return"
for additional details on specifying the response fieldmask.
Example Response
As long as speedReadingIntervals
are requested via the field mask, they are populated under routes.travelAdvisory.speedReadingIntervals
.
The leg level traffic is available under routes.legs.travelAdvisory.speedReadingIntervals
.
Every interval is described by its startPolylinePointIndex
, endPolylinePointIndex
, and the corresponding speed category.
Note that the lack of start index within the interval
corresponds with index 0 in accordance with the proto3 practices.
{
"routes": [
{
"legs": {
"polyline": {
"encodedPolyline": "}boeF~zbjVAg@EmB`GWHlD"
},
"travelAdvisory": {
"speedReadingIntervals": [
{
"endPolylinePointIndex": 1,
"speed": "NORMAL"
},
{
"startPolylinePointIndex": 1,
"endPolylinePointIndex": 2,
"speed": "SLOW"
},
{
"startPolylinePointIndex": 2,
"endPolylinePointIndex": 4,
"speed": "NORMAL"
}
]
}
},
"polyline": {
"encodedPolyline": "}boeF~zbjVAg@EmB`GWHlD"
},
"travelAdvisory": {
"speedReadingIntervals": [
{
"endPolylinePointIndex": 1,
"speed": "NORMAL"
},
{
"startPolylinePointIndex": 1,
"endPolylinePointIndex": 2,
"speed": "SLOW"
},
{
"startPolylinePointIndex": 2,
"endPolylinePointIndex": 4,
"speed": "NORMAL"
}
]
}
}
]
}
Render Traffic Aware Polylines with Maps SDK
We recommend displaying traffic aware polylines on the map using the various features offered by Google Maps SDKs including custom coloring, strokes, and patterns along the polyline streches.
For more details about using polylines, see Polyline Features for Android and Polyline Features for iOS.
Example Polyline rendering
The users of Maps SDK have the opportunity of defining a customized mapping logic between the speed categories and the polyline rendering schemas.
As an example, one might decide to display "NORMAL" speed as a thick blue line on the map while "SLOW" speed might be displayed as a thick orange line, and so on.
The following snippets add a thick blue polyline with geodesic segments from
Melbourne to Perth. For more information, see Customizing appearances (for Android) and Customize the Polyline (for iOS).
Android
Java
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(-37.81319, 144.96298), new LatLng(-31.95285, 115.85734))
.width(25)
.color(Color.BLUE)
.geodesic(true));
Kotlin
val line: Polyline = map.addPolyline(
PolylineOptions()
.add(LatLng(-37.81319, 144.96298), LatLng(-31.95285, 115.85734))
.width(25f)
.color(Color.BLUE)
.geodesic(true)
)
iOS
Objective-C
GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-37.81319 longitude:144.96298];
[path addLatitude:-31.95285 longitude:115.85734];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 10.f;
polyline.strokeColor = .blue;
polyline.geodesic = YES;
polyline.map = mapView;
Swift
let path = GMSMutablePath()
path.addLatitude(-37.81319, longitude: 144.96298)
path.addLatitude(-31.95285, longitude: 115.85734)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 10.0
polyline.geodesic = true
polyline.map = mapView
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe Routes Preferred API allows you to request traffic information along a route's polyline, categorized as NORMAL, SLOW, or TRAFFIC_JAM, using speed reading intervals.\u003c/p\u003e\n"],["\u003cp\u003eTraffic information is available at both the route and leg level, accessible through the \u003ccode\u003espeedReadingIntervals\u003c/code\u003e field within the API response.\u003c/p\u003e\n"],["\u003cp\u003eTo receive traffic data, include \u003ccode\u003epolyline\u003c/code\u003e and \u003ccode\u003espeedReadingIntervals\u003c/code\u003e in the response field mask when making API requests.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Maps SDKs enable the visualization of traffic-aware polylines with custom styling based on speed categories, such as color-coding road segments.\u003c/p\u003e\n"]]],["The Routes Preferred API provides traffic condition information along a polyline, categorized as NORMAL, SLOW, or TRAFFIC_JAM. This data is accessible at both route and leg levels by including `polyline` and `speedReadingIntervals` in the request's field mask. The response contains `speedReadingIntervals` with `startPolylinePointIndex`, `endPolylinePointIndex`, and the speed category. Google Maps SDKs allow users to customize polyline display, such as color and thickness, based on these speed categories.\n"],null,["# Request Traffic Information on the Polyline\n\nThe Routes Preferred API offers the possibility of requesting information about traffic conditions\nalong the polyline. Traffic conditions are expressed in terms of speed categories (NORMAL, SLOW, TRAFFIC_JAM)\napplicable on a given interval of the response polyline. The intervals are defined by the indexes of their starting (inclusive) and ending\n(exclusive) polyline points.\n\nExample Request\n---------------\n\nTraffic aware polyline is available for both route level and leg level.\nAt the route level, the traffic speed information is provided as\n[SpeedReadingIntervals](/maps/documentation/routes_preferred/reference/rest/Shared.Types/SpeedReadingInterval)\nunder the [RouteTravelAdvisory](/maps/documentation/routes_preferred/reference/rest/Shared.Types/RouteTravelAdvisory) response field.\nIn order to receive traffic information alongside the\npolyline of the route, include both `polyline` and `speedReadingIntervals` in the response field mask.\n\nIf the field mask contains `routes.legs.travelAdvisory.speedReadingIntervals`, then the response will contain the leg level traffic data under\n[RouteLegTravelAdvisory](/maps/documentation/routes_preferred/reference/rest/Shared.Types/ComputeRoutesResponse#routelegtraveladvisory). \n\n```text\nX-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline,routes.travelAdvisory.speedReadingIntervals,routes.legs.polyline.encodedPolyline,routes.legs.travelAdvisory.speedReadingIntervals\n```\n\nVisit [\"Choose Fields to Return\"](/maps/documentation/routes_preferred/choose_fields)\nfor additional details on specifying the response fieldmask.\n\nExample Response\n----------------\n\nAs long as `speedReadingIntervals` are requested via the field mask, they are populated under `routes.travelAdvisory.speedReadingIntervals`.\nThe leg level traffic is available under `routes.legs.travelAdvisory.speedReadingIntervals`.\nEvery interval is described by its `startPolylinePointIndex`, `endPolylinePointIndex`, and the corresponding speed category.\nNote that the lack of start index within the interval\ncorresponds with index 0 in accordance with the [proto3 practices](https://developers.google.com/protocol-buffers/docs/proto3#default). \n\n```transact-sql\n{\n \"routes\": [\n {\n \"legs\": {\n \"polyline\": {\n \"encodedPolyline\": \"}boeF~zbjVAg@EmB`GWHlD\"\n },\n \"travelAdvisory\": {\n \"speedReadingIntervals\": \\[\n {\n \"endPolylinePointIndex\": 1,\n \"speed\": \"NORMAL\"\n },\n {\n \"startPolylinePointIndex\": 1,\n \"endPolylinePointIndex\": 2,\n \"speed\": \"SLOW\"\n },\n {\n \"startPolylinePointIndex\": 2,\n \"endPolylinePointIndex\": 4,\n \"speed\": \"NORMAL\"\n }\n ] \n }\n },\n \"polyline\": {\n \"encodedPolyline\": \"}boeF~zbjVAg@EmB`GWHlD\"\n },\n \"travelAdvisory\": {\n \"speedReadingIntervals\": [\n {\n \"endPolylinePointIndex\": 1,\n \"speed\": \"NORMAL\"\n },\n {\n \"startPolylinePointIndex\": 1,\n \"endPolylinePointIndex\": 2,\n \"speed\": \"SLOW\"\n },\n {\n \"startPolylinePointIndex\": 2,\n \"endPolylinePointIndex\": 4,\n \"speed\": \"NORMAL\"\n }\n ] \n }\n }\n ]\n}\n```\n\nRender Traffic Aware Polylines with Maps SDK\n============================================\n\nWe recommend displaying traffic aware polylines on the map using the various features offered by Google Maps SDKs including custom coloring, strokes, and patterns along the polyline streches.\nFor more details about using polylines, see [Polyline Features for Android](/maps/documentation/android-sdk/polygon-tutorial#java_4) and [Polyline Features for iOS](/maps/documentation/ios-sdk/shapes).\n\nExample Polyline rendering\n--------------------------\n\nThe users of Maps SDK have the opportunity of defining a customized mapping logic between the speed categories and the polyline rendering schemas.\nAs an example, one might decide to display \"NORMAL\" speed as a thick blue line on the map while \"SLOW\" speed might be displayed as a thick orange line, and so on.\n\nThe following snippets add a thick blue polyline with geodesic segments from\nMelbourne to Perth. For more information, see [Customizing appearances](/maps/documentation/android-sdk/polygon-tutorial#add_custom_styling_to_your_polyline) (for Android) and [Customize the Polyline](/maps/documentation/ios-sdk/shapes#customize-a-polyline) (for iOS).\n\n### Android\n\n### Java\n\n\n```java\nPolyline line = map.addPolyline(new PolylineOptions()\n .add(new LatLng(-37.81319, 144.96298), new LatLng(-31.95285, 115.85734))\n .width(25)\n .color(Color.BLUE)\n .geodesic(true));\n```\n\n\u003cbr /\u003e\n\n### Kotlin\n\n\n```kotlin\nval line: Polyline = map.addPolyline(\n PolylineOptions()\n .add(LatLng(-37.81319, 144.96298), LatLng(-31.95285, 115.85734))\n .width(25f)\n .color(Color.BLUE)\n .geodesic(true)\n)\n```\n\n\u003cbr /\u003e\n\n### iOS\n\n### Objective-C\n\n\n```objective-c\nGMSMutablePath *path = [GMSMutablePath path];\n[path addLatitude:-37.81319 longitude:144.96298];\n[path addLatitude:-31.95285 longitude:115.85734];\nGMSPolyline *polyline = [GMSPolyline polylineWithPath:path];\npolyline.strokeWidth = 10.f;\npolyline.strokeColor = .blue;\npolyline.geodesic = YES;\npolyline.map = mapView;\n```\n\n\u003cbr /\u003e\n\n### Swift\n\n\n```swift\nlet path = GMSMutablePath()\npath.addLatitude(-37.81319, longitude: 144.96298)\npath.addLatitude(-31.95285, longitude: 115.85734)\nlet polyline = GMSPolyline(path: path)\npolyline.strokeWidth = 10.0\npolyline.geodesic = true\npolyline.map = mapView\n```\n\n\u003cbr /\u003e"]]