Stay organized with collections
Save and categorize content based on your preferences.
Search along route
To use Text Search (New) to search along a route, pass the precalculated route
from the Routes API in
the request as a polyline. The response contains places that match the search
criteria and are also located near the specified route.
Use SearchAlongRouteParameters.setPolyline() to
pass the route's encoded 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.
By default, Text Search (New) performs the search along the entire route from
the origin to the destination as defined by the polyline. In the following
example, the polyline defines the route from:
Origin: 1600 Amphitheatre Parkway, Mountain View, CA
Destination: 24 Willie Mays Plaza, San Francisco, CA
The trip's encoded polyline for this route is represented by the string:
The following example uses the route's encoded polyline to bias the search
results:
// Define the route polyline object using the route string.EncodedPolylineencodedPolyline=EncodedPolyline.newInstance("wblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb@[`@{GhHeEdEciBnnBkC`DkC~DaClEuKjT_Z|l@Qb@iR~_@}EzJ_AdB_Und@kAfCaOjZkg@vcAqBzD_]rr@iBlEaBxEgArD}AlG}AhHsA`IeAnH{@dIq@dJgL~iBq@rHu@vGgAtHwArHaBhHkBzG_DpJ}Nbc@iBhGkA|EgC|LcIjb@oAhG_AvDgAdDkApC_BzCiBpCsFvGii@vn@scAxlAmLjNgSzUeRjT{TzWqExEmG|FuNlMmMhLaRvPqOlNmbAl}@mFlF{PlOmJfIoElE}LtMiSbU_H`I}}@jcAwl@vp@oAbBqA~BeAhCm@tBg@fCWrBQ~BI|DaB~rBO~D[bEa@`Dm@pDaAdE{@vC_BbEkB~Def@|z@sEzHKJeS~]}K`S{\\~l@cXpe@sBpDm@bAuCxDkBrBiC~BwCtByBnAcBx@}Bt@{Bn@gh@|LaOpDeFhAoDj@aE^kVrA_E^iEr@yD~@uBr@gMjF_EnAcCh@eFr@_DRsAD}@Jsu@xCWDqIV}BCeCOyDm@cBa@_DmA}JeE_CwAsBcBiBoBuAqBmOoX{CuEkB_CoDqDkVoUoD{CeE_DkEkC_FeCqB}@sDuAoDgAeCe@cCW}CK}BDaDTeOlBcuBrYaNlBq@Dyd@rGyFt@yBb@eBf@oCnAoBlAkIpGkAp@wBbAaCt@oFdAwKjBoGxA{FbByIjC_HfB_@KmNdDuC|@uFzBcH|C{@\\[?sBv@}@VaBVoA@y@EmAQcA[w@]aBkAeAkA}BuDUKs@uAqBsCwBcCgAiAiN_MyKsJsG{GkBaBiBuA{BwAwDkBcOaHiC_AiCg@}BQcCAcBHqBVkB`@qEjAu@LgCVgAHwG@sG?mABsH^eNr@mBXy@NqBt@uAt@aBlAkAlA}BtCyApBiAdB_BxB{A`B}@j@oAf@s@PeCVcIf@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C");// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.NAME);// Define the search along route parameters object and pass the polyline object.SearchAlongRouteParameterssearchAlongRouteParameters=SearchAlongRouteParameters.builder().setPolyline(encodedPolyline).build();// Use the builder to create a SearchByTextRequest object and pass the search along route parameters.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food",placeFields).setMaxResultCount(10).setSearchAlongRouteParameters(searchAlongRouteParameters).build();// Call PlacesClient.searchByText() to perform the search.// Define a response handler to process the returned List of Place objects.placesClient.searchByText(searchByTextRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();});
The SearchByTextResponse class represents the response from a search request.
A SearchByTextResponse object contains:
A list of Place objects that represent all matching places, with one Place object per matching place.
Each Place object only contains the fields defined by the field list passed in the request.
You don't have to bias the results to the entire route. For example, you might already be halfway
along the route before you perform the search. In this case, you can specify an explicit routing
origin to the search to override the origin defined in the encoded polyline. In the following
example, you specify the latitude and longitude coordinates of San Mateo, CA, which is
approximately halfway along the route polyline:
// Define the route polyline object using the route string.EncodedPolylineencodedPolyline=EncodedPolyline.newInstance("wblcFptchV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iAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C");// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.NAME);// Define the routing parameters object and pass the routing origin.RoutingParametersroutingParameters=RoutingParameters.builder().setOrigin(toLatLng("37.56617, -122.30870")).build();// Define the search along route parameters object and pass the polyline object.SearchAlongRouteParameterssearchAlongRouteParameters=SearchAlongRouteParameters.builder().setPolyline(encodedPolyline).build();// Use the builder to create a SearchByTextRequest object and pass the search along route and routing parameters.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food",placeFields).setMaxResultCount(10).setRoutingParameters(routingParameters).setSearchAlongRouteParameters(searchAlongRouteParameters).build();// Call PlacesClient.searchByText() to perform the search.// Define a response handler to process the returned List of Place objects.placesClient.searchByText(searchByTextRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();});
Try it!
The APIs Explorer lets you make sample requests so
that you can get familiar with the API and the API options.
Select the API icon api
on the right side of the page.
Optionally edit the request parameters.
Select the Execute button. In the dialog, choose the account
that you want to use to make the request.
In the APIs Explorer panel, select the fullscreen icon
fullscreen to expand the APIs Explorer window.
[[["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-08-28 UTC."],[[["\u003cp\u003eSearch along a route using Text Search (New) by providing a precalculated route polyline from the Routes API.\u003c/p\u003e\n"],["\u003cp\u003eThe response includes places matching your search terms located near the provided route, prioritizing minimal detour times.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify a starting point along the route to bias results for searches conducted mid-route.\u003c/p\u003e\n"],["\u003cp\u003eText Search (New) uses an encoded polyline to represent the route for efficient processing and compression.\u003c/p\u003e\n"],["\u003cp\u003eThe SearchByTextResponse object contains a list of Place objects, each containing details about a matching place based on requested fields.\u003c/p\u003e\n"]]],["To search along a route using Text Search (New), first calculate a route with the Routes API, ensuring it returns an encoded polyline. Then, use `SearchAlongRouteParameters.setPolyline()` to pass this polyline to Text Search, biasing results to places near the route. By default, the search covers the entire route, but an alternative origin can be set with `RoutingParameters` to search along a portion of the route. Initiate the search by constructing the `SearchByTextRequest` object with the polyline and other optional parameters, then by calling the `searchByText` function.\n"],null,["Search along route\n==================\n\nTo use [Text Search (New)](/maps/documentation/places/android-sdk/text-search) to search along a route, pass the precalculated route\nfrom the [Routes API](/maps/documentation/routes/compute_route_directions) in\nthe request as a polyline. The response contains places that match the search\ncriteria and are also located near the specified route.\n\nTo search along a route:\n\n1. Use the Routes API to calculate a route that [returns a route's encoded\n polyline](/maps/documentation/routes/traffic_on_polylines) in the response.\n\n | **Note:** You can also encode your own polyline as described in [Encoded\n | Polyline Algorithm Format](/maps/documentation/utilities/polylinealgorithm).\n2. Use `SearchAlongRouteParameters.setPolyline()` to\n pass the route's encoded polyline to Text Search (New) to bias the search\n results to the route. The response then contains places that match the\n search criteria and are also located near the specified route.\n\nBy default, Text Search (New) performs the search along the entire route from\nthe origin to the destination as defined by the polyline. In the following\nexample, the polyline defines the route from:\n\n- **Origin**: 1600 Amphitheatre Parkway, Mountain View, CA\n- **Destination**: 24 Willie Mays Plaza, San Francisco, CA\n\nThe trip's encoded polyline for this route is represented by the string: \n\n```yaml\nwblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb@[`@{GhHeEdEciBnnBkC`DkC~DaClEuKjT_Z|l@Qb@iR~_@}EzJ_AdB_Und@kAfCaOjZkg@vcAqBzD_]rr@iBlEaBxEgArD}AlG}AhHsA`IeAnH{@dIq@dJgL~iBq@rHu@vGgAtHwArHaBhHkBzG_DpJ}Nbc@iBhGkA|EgC|LcIjb@oAhG_AvDgAdDkApC_BzCiBpCsFvGii@vn@scAxlAmLjNgSzUeRjT{TzWqExEmG|FuNlMmMhLaRvPqOlNmbAl}@mFlF{PlOmJfIoElE}LtMiSbU_H`I}}@jcAwl@vp@oAbBqA~BeAhCm@tBg@fCWrBQ~BI|DaB~rBO~D[bEa@`Dm@pDaAdE{@vC_BbEkB~Def@|z@sEzHKJeS~]}K`S{\\\\~l@cXpe@sBpDm@bAuCxDkBrBiC~BwCtByBnAcBx@}Bt@{Bn@gh@|LaOpDeFhAoDj@aE^kVrA_E^iEr@yD~@uBr@gMjF_EnAcCh@eFr@_DRsAD}@Jsu@xCWDqIV}BCeCOyDm@cBa@_DmA}JeE_CwAsBcBiBoBuAqBmOoX{CuEkB_CoDqDkVoUoD{CeE_DkEkC_FeCqB}@sDuAoDgAeCe@cCW}CK}BDaDTeOlBcuBrYaNlBq@Dyd@rGyFt@yBb@eBf@oCnAoBlAkIpGkAp@wBbAaCt@oFdAwKjBoGxA{FbByIjC_HfB_@KmNdDuC|@uFzBcH|C{@\\\\[?sBv@}@VaBVoA@y@EmAQcA[w@]aBkAeAkA}BuDUKs@uAqBsCwBcCgAiAiN_MyKsJsG{GkBaBiBuA{BwAwDkBcOaHiC_AiCg@}BQcCAcBHqBVkB`@qEjAu@LgCVgAHwG@sG?mABsH^eNr@mBXy@NqBt@uAt@aBlAkAlA}BtCyApBiAdB_BxB{A`B}@j@oAf@s@PeCVcIf@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C\n```\n| **Note:** Search along route only supports an encoded polyline, which can be passed as a string and includes compression with minimal lossiness. This is the Routes API default output. For more information, see [Request route\n| polylines](/maps/documentation/routes/traffic_on_polylines).\n\nThe following example uses the route's encoded polyline to bias the search\nresults: \n\n```java\n// Define the route polyline object using the route string.\nEncodedPolyline encodedPolyline = EncodedPolyline.newInstance(\"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f@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C\");\n\n// Specify the list of fields to return.\nfinal List\u003cPlace.Field\u003e placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);\n\n// Define the search along route parameters object and pass the polyline object.\nSearchAlongRouteParameters searchAlongRouteParameters = SearchAlongRouteParameters.builder()\n .setPolyline(encodedPolyline)\n .build();\n\n// Use the builder to create a SearchByTextRequest object and pass the search along route parameters.\nfinal SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder(\"Spicy Vegetarian Food\", placeFields)\n .setMaxResultCount(10)\n .setSearchAlongRouteParameters(searchAlongRouteParameters)\n .build();\n\n// Call PlacesClient.searchByText() to perform the search.\n// Define a response handler to process the returned List of Place objects.\nplacesClient.searchByText(searchByTextRequest) \n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n });\n```\n\nThe [`SearchByTextResponse`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/SearchByTextResponse) class represents the response from a search request.\nA `SearchByTextResponse` object contains:\n\n- A list of `Place` objects that represent all matching places, with one `Place` object per matching place.\n- Each `Place` object only contains the fields defined by the field list passed in the request.\n\nYou don't have to bias the results to the entire route. For example, you might already be halfway\nalong the route before you perform the search. In this case, you can specify an explicit routing\norigin to the search to override the origin defined in the encoded polyline. In the following\nexample, you specify the latitude and longitude coordinates of San Mateo, CA, which is\napproximately halfway along the route polyline: \n\n```java\n// Define the route polyline object using the route string.\nEncodedPolyline encodedPolyline = EncodedPolyline.newInstance(\"wblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb@[`@{GhHeEdEciBnnBkC`DkC~DaClEuKjT_Z|l@Qb@iR~_@}EzJ_AdB_Und@kAfCaOjZkg@vcAqBzD_]rr@iBlEaBxEgArD}AlG}AhHsA`IeAnH{@dIq@dJgL~iBq@rHu@vGgAtHwArHaBhHkBzG_DpJ}Nbc@iBhGkA|EgC|LcIjb@oAhG_AvDgAdDkApC_BzCiBpCsFvGii@vn@scAxlAmLjNgSzUeRjT{TzWqExEmG|FuNlMmMhLaRvPqOlNmbAl}@mFlF{PlOmJfIoElE}LtMiSbU_H`I}}@jcAwl@vp@oAbBqA~BeAhCm@tBg@fCWrBQ~BI|DaB~rBO~D[bEa@`Dm@pDaAdE{@vC_BbEkB~Def@|z@sEzHKJeS~]}K`S{\\\\~l@cXpe@sBpDm@bAuCxDkBrBiC~BwCtByBnAcBx@}Bt@{Bn@gh@|LaOpDeFhAoDj@aE^kVrA_E^iEr@yD~@uBr@gMjF_EnAcCh@eFr@_DRsAD}@Jsu@xCWDqIV}BCeCOyDm@cBa@_DmA}JeE_CwAsBcBiBoBuAqBmOoX{CuEkB_CoDqDkVoUoD{CeE_DkEkC_FeCqB}@sDuAoDgAeCe@cCW}CK}BDaDTeOlBcuBrYaNlBq@Dyd@rGyFt@yBb@eBf@oCnAoBlAkIpGkAp@wBbAaCt@oFdAwKjBoGxA{FbByIjC_HfB_@KmNdDuC|@uFzBcH|C{@\\\\[?sBv@}@VaBVoA@y@EmAQcA[w@]aBkAeAkA}BuDUKs@uAqBsCwBcCgAiAiN_MyKsJsG{GkBaBiBuA{BwAwDkBcOaHiC_AiCg@}BQcCAcBHqBVkB`@qEjAu@LgCVgAHwG@sG?mABsH^eNr@mBXy@NqBt@uAt@aBlAkAlA}BtCyApBiAdB_BxB{A`B}@j@oAf@s@PeCVcIf@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C\");\n\n// Specify the list of fields to return.\nfinal List\u003cPlace.Field\u003e placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);\n\n// Define the routing parameters object and pass the routing origin.\nRoutingParameters routingParameters = RoutingParameters.builder()\n .setOrigin(toLatLng(\"37.56617, -122.30870\"))\n .build();\n\n// Define the search along route parameters object and pass the polyline object.\nSearchAlongRouteParameters searchAlongRouteParameters = SearchAlongRouteParameters.builder()\n .setPolyline(encodedPolyline)\n .build();\n\n// Use the builder to create a SearchByTextRequest object and pass the search along route and routing parameters.\nfinal SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder(\"Spicy Vegetarian Food\", placeFields)\n .setMaxResultCount(10)\n .setRoutingParameters(routingParameters)\n .setSearchAlongRouteParameters(searchAlongRouteParameters)\n .build();\n\n// Call PlacesClient.searchByText() to perform the search.\n// Define a response handler to process the returned List of Place objects.\nplacesClient.searchByText(searchByTextRequest) \n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n });\n```\n| **Note:** Because search along route returns places with minimal detour times from origin to destination, in cases where the route origin and destination are the same or close to one another, search along route may not return any results.\n\nTry it!\n-------\n\nThe APIs Explorer lets you make sample requests so\nthat you can get familiar with the API and the API options.\n\n1. Select the API icon api\n on the right side of the page.\n\n2. Optionally edit the request parameters.\n\n3. Select the **Execute** button. In the dialog, choose the account\n that you want to use to make the request.\n\n4. In the APIs Explorer panel, select the fullscreen icon\n fullscreen to expand the APIs Explorer window."]]