Work with polylines Stay organized with collections Save and categorize content based on your preferences.
ThecomputeRoutes method returns the route represented by a polyline as part of the response. You can request two types of polylines:
- Basic polyline (default), represents a route but without traffic information embedded in the polyline. Requests that return a basic polyline are billed at the Routes Basic rate.Learn more about billing for Routes API.
- Traffic-aware polyline, contains information about the traffic conditions along the route. Traffic conditions are expressed in terms of speed categories (
NORMAL,SLOW,TRAFFIC_JAM) applicable on a given interval of the polyline. Requests for traffic-aware polylines are billed at the Routes Preferred rate.Learn more about billing for Routes API. - Multimodal polyline, contains transit details as well as traffic information. Requests for multimodal polylines are billed at the Routes Preferred rate.Learn more about billing for Routes API.
Basic polyline (default)
A polyline is represented by aPolyline object; a path is an array ofLatLngAltitude coordinates. To return a basic polyline, call thecomputeRoutes method with thefields property set topath, then call thecreatePolylines method on the route instance to get aPolyline object.
The following example shows how to request a basic polyline:
// Define a basic routes request.constrequestWithBasicPolyline={origin:'155 Steuart St, San Francisco, CA 94105',destination:'450 Powell St, San Francisco, CA 94102',travelMode:'WALKING',fields:['path'],// Request path field to get a polyline.};
Traffic-aware polyline
To request a traffic-aware polyline, add the following properties to your request:
- Set the
travelModeproperty toDRIVING. - Set the
routingPreferenceproperty toTRAFFIC_AWARE. - Set the
extraComputationsproperty toTRAFFIC_ON_POLYLINE. - Specify the
path,speedPaths, androuteLabelsfields.
The following example shows how to request a traffic-aware polyline:
// Define a traffic aware routes request.constrequestWithTraffic={origin:'200 King St San Francisco, CA 94107',destination:'Pier 41, San Francisco, CA 94133',travelMode:'DRIVING',routingPreference:'TRAFFIC_AWARE',extraComputations:['TRAFFIC_ON_POLYLINE'],fields:['speedPaths'],};
Display polylines on a map
To display polylines on a map, callcreatePolylines on the route object, then use thesetMap method to set the polyline's map to the map object. The map object is used to display the polyline on the map.
The following example shows how to show a polyline on a map:
// Call createPolylines to create polylines for the first route.mapPolylines=routes[0].createPolylines();// Add polylines to the map.mapPolylines.forEach((polyline)=>polyline.setMap(map));
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-31 UTC.