Combine routing summaries with search along route
You can combinerouting summary calculations withsearch along a route.In this case,Text Search (New) returns the travel duration and distance to eachplace in the response, and then from each place to the final destination of theroute.
To use Text Search (New) to calculate the routing summary along with searchalong a route:
Use the Routes API to calculate a route thatreturns a route polyline in the response.
Use the
searchAlongRouteParameters.polyline.encodedPolylineparameter to pass the route polyline to Text Search (New) to bias the search results to the route. The response then contains places that match the search criteria and are also located near the specified route.Include
Note: AddingroutingSummariesin the field mask so that the response includes theroutingSummariesarray. This array contains the duration and distance from the routing origin to each place in the response.routingSummariesin the field mask without also including either theroutingParameters.originparameter or thesearchAlongRouteParameters.polyline.encodedPolylineparameter in the request causes an error.
The APIs Explorer lets you make live requests so that you can get familiar withthe API and the API options:
By default, Text Search (New) performs the search along the entire route:
curl -X POST -d '{ "textQuery" : "Spicy Vegetarian Food","searchAlongRouteParameters": { "polyline": { "encodedPolyline": "ROUTE_POLYLINE" } }}' \-H 'Content-Type: application/json' -H 'X-Goog-Api-Key:API_KEY' \-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel,routingSummaries' \'https://places.googleapis.com/v1/places:searchText'The response contains two arrays: theplaces array containing the matchingplaces, and theroutingSummaries array containing the duration and distance totravel to each place:
{"places":[{"formattedAddress":"1199 El Camino Real, San Bruno, CA 94066, USA","priceLevel":"PRICE_LEVEL_INEXPENSIVE","displayName":{"text":"Vegan Mob - Vegan BBQ and Soul Food","languageCode":"en"}},{"formattedAddress":"839 Kearny St, San Francisco, CA 94108, USA","priceLevel":"PRICE_LEVEL_MODERATE","displayName":{"text":"Enjoy Vegetarian","languageCode":"en"}},…],"routingSummaries":[{"legs":[{"duration":"285s","distanceMeters":1616},{"duration":"2466s","distanceMeters":58147}],"directionsUri":"https://www.google.com/maps/dir/37.42268,-122.08473/''/37.77877,-122.38781/data=!4m7!4m6!1m0!1m2!1m1!1s0x808f87f9ede375f5:0xa37171fea1a16b28!1m0!3e0"},{"legs":[{"duration":"696s","distanceMeters":4704},{"duration":"2787s","distanceMeters":58901}],"directionsUri":"https://www.google.com/maps/dir/37.42268,-122.08473/''/37.77877,-122.38781/data=!4m7!4m6!1m0!1m2!1m1!1s0x808580f4cebdb06f:0xd3af09e5742234f2!1m0!3e0"},…]}
For each entry in thelegs array, Text Search (New) returns atwo-leg triptime:
The first leg contains the travel duration and distance from the origin to the place. In this example, the duration and distance from the origin to the first place in the results is 285 seconds and 1616 meters.
The second leg contains the travel duration and distance from the place to the route destination. In this example, the duration and distance is 2466 seconds and 58147 meters.
directionsUri field in the routing summary for each place. This field contains a linkto open directions to the place in Google Maps. The polyline origin or theroutingParameters.origin parameter specifies directions origin, thepolyline destination specifies the directions destination, and the travel mode is drive.The directions start at the origin, proceed to the place as a waypoint, and end at the routedestination.This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by theGoogle Maps Platform Service Specific Terms. For more information, see thelaunch stage descriptions.Specify the routing origin, travel mode, and route modifiers
You can modify the search and routing summary calculation by specifying therouting origin, travel mode, route modifiers, and routing preferences. Thetravel mode and route modifiers work the same as for calculating routingsummaries without specifying a route as shown in theSpecify traveloptions topic.
By default, the first leg of each result contains the distance from the origindefined by the polyline to each place. However, you can override that default byexplicitly specifying a routing origin in the request. If specified, the firstleg of all responses specifies the distances and duration from the specifiedrouting origin, overriding the origin from the polyline.
In the next example, you specify a routing origin as the coordinates of SanMateo, CA, specify to avoid tolls, and set the number of results to 5:
curl -X POST -d '{ "textQuery" : "Spicy Vegetarian Food", "maxResultCount": 5,"searchAlongRouteParameters": { "polyline": { "encodedPolyline": "ROUTE_POLYLINE" } }, "routingParameters": { "origin": { "latitude": 37.56617, "longitude": -122.30870 }, "travelMode":"DRIVE", "routeModifiers": { "avoidTolls": true } } }' \ -H 'Content-Type: application/json' -H 'X-Goog-Api-Key:API_KEY' \ -H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel,routingSummaries' \ 'https://places.googleapis.com/v1/places:searchText'The following image shows a map that contains the route polyline, the new origin(light-blue pin), and the places in the search results (green pins). Notice howall the results are along the route, but past San Mateo:

Try it!
The APIs Explorer lets you make sample requests sothat you can get familiar with the API and the API options.
Select the API iconapi on the right side of the page.
Optionally edit the request parameters.
Select theExecute button. In the dialog, choose the account that you want to use to make the request.
In the APIs Explorer panel, select the fullscreen iconfullscreen to expand the APIs Explorer window.
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-11-21 UTC.