Pass the RoutingParameters parameter in the request, using
setOrigin() to specify the latitude and longitude coordinates of the routing
origin. This parameter is required to calculate the duration and distance to each place in the
response.
When building the request object, add .setRoutingSummariesIncluded(true).
Use Text Search (New)
In the following request, you calculate the travel duration and distance to each
place in the Text Search (New) response:
// 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("-33.8688, 151.1957362")).build();// Use the builder to create a SearchByTextRequest object and pass the routing parameters.// Set setRoutingSummariesIncluded to true.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food in Sydney, Australia",placeFields).setMaxResultCount(10).setRoutingParameters(routingParameters).setRoutingSummariesIncluded(true).build();// Call PlacesClient.searchByText() to perform the search.// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.placesClient.searchByText(searchByTextRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();List<RoutingSummary>routingSummaries=response.getRoutingSummaries();List<Leg>legs=routingSummaries.get(0).getLegs();Durationduration=legs.get(0).getDuration();});
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.
Use Nearby Search
In this example, you calculate the travel duration and distance to each place in
the Nearby Search response. This example searches for restaurants in Sydney,
Australia and sets the location restriction and the routing origin to the same
latitude and longitude coordinate:
// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.NAME);// Define the search area as a 500 meter diameter circle in Sydney, Australia.LatLngcenter=newLatLng(-33.8688,151.1957362);CircularBoundscircle=CircularBounds.newInstance(center,/* radius = */500);// Define the routing parameters object and pass the routing origin.RoutingParametersroutingParameters=RoutingParameters.builder().setOrigin(toLatLng("-33.8688, 151.1957362")).build();// Use the builder to create a SearchNearbyRequest object and pass the routing parameters.// Set setRoutingSummariesIncluded to true.finalSearchNearbyRequestsearchNearbyRequest=SearchNearbyRequest.builder(/* location restriction = */circle,placeFields).setIncludedTypes(includedTypes).setMaxResultCount(10).setRoutingParameters(routingParameters).setRoutingSummariesIncluded(true).build();// Call PlacesClient.searchNearby() to perform the search.// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.placesClient.searchNearby(searchNearbyRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();List<RoutingSummary>routingSummaries=response.getRoutingSummaries();List<Leg>legs=routingSummaries.get(0).getLegs();Durationduration=legs.get(0).getDuration();});
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 use the same coordinates for the location restriction and the
for routing origin. For example, you set the locations restriction to the center
point of Sydney to restrict the search results to that circle. But you then set the
routing origin to the coordinates of your house, meaning to a different location
within the search circle. The request then restricts the search results to the
circle, and calculates the routing summaries based on the location of your
house.
Specify travel options
By default, the duration and distance calculations are for a car. However, you
can control the vehicle type, as well as other options, in the search.
Use routingParameters.setTravelMode() to set the mode of
transportation to DRIVE, BICYCLE, WALK, or TWO_WHEELER. For more
information on these options, see Available vehicle types for
routes.
Use routingParameters.setRoutingPreference() to set the routing
preference option to TRAFFIC_UNAWARE (default), TRAFFIC_AWARE, or
TRAFFIC_AWARE_OPTIMAL. Each option has varying levels of data quality and
latency. For more information, see Specify how and if to include traffic
data.
Use routingParameters.setRouteModifiers() to specify to
avoidTolls, avoidHighways, avoidFerries, and avoidIndoor. For more
information on these options, see Specify route features to
avoid.
In the next example, you specify the travel mode as DRIVE and to avoid
highways:
// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.NAME);// Define the routing modifiers object.RouteModifiersrouteModifiers=RouteModifiers.builder().setAvoidHighways(true).build();// Define the routing parameters object and pass the routing origin.RoutingParametersroutingParameters=RoutingParameters.builder().setOrigin(toLatLng("-33.8688, 151.1957362")).setTravelMode(DRIVE).setRouteModifiers(routeModifiers).build();// Use the builder to create a SearchByTextRequest object and pass the routing parameters.// Set setRoutingSummariesIncluded to true.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food in Sydney, Australia",placeFields).setMaxResultCount(10).setRoutingParameters(routingParameters).setRoutingSummariesIncluded(true).build();// Call PlacesClient.searchByText() to perform the search.// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.placesClient.searchByText(searchByTextRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();List<RoutingSummary>routingSummaries=result.getRoutingSummaries();List<Leg>legs=routingSummaries.get(0).getLegs();Durationduration=legs.get(0).getDuration();});
[[["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-03 UTC."],[[["\u003cp\u003eCalculate travel duration and distance to places using Text Search (New) or Nearby Search (New) by specifying an origin and enabling routing summaries in your request.\u003c/p\u003e\n"],["\u003cp\u003eAccess the calculated duration and distance through the \u003ccode\u003eRoutingSummary\u003c/code\u003e objects returned in the API response, which include \u003ccode\u003eduration\u003c/code\u003e and \u003ccode\u003edistanceMeters\u003c/code\u003e for each place.\u003c/p\u003e\n"],["\u003cp\u003eCustomize route calculations by specifying travel mode (DRIVE, BICYCLE, WALK, TWO_WHEELER), routing preference (TRAFFIC_UNAWARE, TRAFFIC_AWARE, TRAFFIC_AWARE_OPTIMAL), and route modifiers (avoidTolls, avoidHighways, avoidFerries, avoidIndoor).\u003c/p\u003e\n"],["\u003cp\u003eNote that the Places API only provides duration and distance, not the full route; to obtain the route itself, use the Routes API with the origin and destination place's location.\u003c/p\u003e\n"]]],["To calculate travel duration and distance to places, use `RoutingParameters` with `setOrigin()`. Include `.setRoutingSummariesIncluded(true)` in the request object. This applies to both `Text Search (New)` and `Nearby Search (New)`. The response provides `duration` and `distanceMeters` via `RoutingSummary` and `Leg` objects. Customize travel by setting the travel mode (e.g., `DRIVE`, `BICYCLE`) with `setTravelMode()` and specify preferences like avoiding highways with `setRouteModifiers()`. Note: the response doesn't include the actual route.\n"],null,["Calculate routing summary\n=========================\n\nTo use [Text Search (New)](/maps/documentation/places/android-sdk/text-search) or [Nearby Search (New)](/maps/documentation/places/android-sdk/nearby-search)\nto calculate the travel duration and distance to each place in the response:\n\n1. Pass the `RoutingParameters` parameter in the request, using\n `setOrigin()` to specify the latitude and longitude coordinates of the routing\n origin. This parameter is required to calculate the duration and distance to each place in the\n response.\n\n2. When building the request object, add `.setRoutingSummariesIncluded(true)`.\n\nUse Text Search (New)\n---------------------\n\nIn the following request, you calculate the travel duration and distance to each\nplace in the Text Search (New) response: \n\n```java\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(\"-33.8688, 151.1957362\"))\n .build();\n\n// Use the builder to create a SearchByTextRequest object and pass the routing parameters.\n// Set setRoutingSummariesIncluded to true.\nfinal SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder(\"Spicy Vegetarian Food in Sydney, Australia\", placeFields)\n .setMaxResultCount(10)\n .setRoutingParameters(routingParameters)\n .setRoutingSummariesIncluded(true)\n .build();\n\n// Call PlacesClient.searchByText() to perform the search.\n// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.\nplacesClient.searchByText(searchByTextRequest) \n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n List\u003cRoutingSummary\u003e routingSummaries = response.getRoutingSummaries();\n List\u003cLeg\u003e legs = routingSummaries.get(0).getLegs();\n Duration duration = legs.get(0).getDuration();\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.\nYou can call [`SearchByTextResponse.getRoutingSummaries()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/SearchByTextResponse#getRoutingSummaries()) to return the list of routing summaries.\nA `SearchByTextResponse` object also 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\n| **Note:** The response only contains the `duration` and `distanceMeters` to each place. It does not contain the actual route itself. To calculate the route, use the Routes API, passing to it the origin and location of the destination place.\n\nUse Nearby Search\n-----------------\n\nIn this example, you calculate the travel duration and distance to each place in\nthe Nearby Search response. This example searches for restaurants in Sydney,\nAustralia and sets the location restriction and the routing origin to the same\nlatitude and longitude coordinate: \n\n```java\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 area as a 500 meter diameter circle in Sydney, Australia.\nLatLng center = new LatLng(-33.8688, 151.1957362);\nCircularBounds circle = CircularBounds.newInstance(center, /* radius = */ 500);\n\n// Define the routing parameters object and pass the routing origin.\nRoutingParameters routingParameters = RoutingParameters.builder()\n .setOrigin(toLatLng(\"-33.8688, 151.1957362\"))\n .build();\n\n// Use the builder to create a SearchNearbyRequest object and pass the routing parameters.\n// Set setRoutingSummariesIncluded to true.\nfinal SearchNearbyRequest searchNearbyRequest =\nSearchNearbyRequest.builder(/* location restriction = */ circle, placeFields)\n .setIncludedTypes(includedTypes)\n .setMaxResultCount(10)\n .setRoutingParameters(routingParameters)\n .setRoutingSummariesIncluded(true)\n .build();\n\n// Call PlacesClient.searchNearby() to perform the search.\n// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.\nplacesClient.searchNearby(searchNearbyRequest)\n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n List\u003cRoutingSummary\u003e routingSummaries = response.getRoutingSummaries();\n List\u003cLeg\u003e legs = routingSummaries.get(0).getLegs();\n Duration duration = legs.get(0).getDuration();\n });\n```\n\nThe [`SearchNearbyResponse`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/SearchNearbyResponse) class represents the response from a search request.\nYou can call [`SearchNearbyResponse.getRoutingSummaries()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/SearchNearbyResponse#getRoutingSummaries()) to return the list of routing summaries.\nA `SearchNearbyResponse` object also 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 use the same coordinates for the location restriction and the\nfor routing origin. For example, you set the locations restriction to the center\npoint of Sydney to restrict the search results to that circle. But you then set the\nrouting origin to the coordinates of your house, meaning to a different location\nwithin the search circle. The request then restricts the search results to the\ncircle, and calculates the routing summaries based on the location of your\nhouse.\n\nSpecify travel options\n----------------------\n\nBy default, the duration and distance calculations are for a car. However, you\ncan control the vehicle type, as well as other options, in the search.\n\n- Use `routingParameters.setTravelMode()` to set the mode of\n transportation to `DRIVE`, `BICYCLE`, `WALK`, or `TWO_WHEELER`. For more\n information on these options, see [Available vehicle types for\n routes](/maps/documentation/routes/vehicles).\n\n | **Note:** The Routes API also supports a mode of `TRANSIT`, but that mode is not supported by the Places API.\n | **Note:** The `TWO_WHEELER` option is only supported in those countries listed at [Countries and regions supported for two-wheeled\n | vehicles](/maps/documentation/routes/coverage-two-wheeled).\n- Use `routingParameters.setRoutingPreference()` to set the routing preference option to `TRAFFIC_UNAWARE` (default), `TRAFFIC_AWARE`, or `TRAFFIC_AWARE_OPTIMAL`. Each option has varying levels of data quality and latency. For more information, see [Specify how and if to include traffic\n data](/maps/documentation/routes/config_trade_offs).\n- Use `routingParameters.setRouteModifiers()` to specify to `avoidTolls`, `avoidHighways`, `avoidFerries`, and `avoidIndoor`. For more information on these options, see [Specify route features to\n avoid](/maps/documentation/routes/route-modifiers).\n\nIn the next example, you specify the travel mode as `DRIVE` and to avoid\nhighways: \n\n```java\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 modifiers object.\nRouteModifiers routeModifiers = RouteModifiers.builder()\n .setAvoidHighways(true)\n .build();\n\n// Define the routing parameters object and pass the routing origin.\nRoutingParameters routingParameters = RoutingParameters.builder()\n .setOrigin(toLatLng(\"-33.8688, 151.1957362\"))\n .setTravelMode(DRIVE)\n .setRouteModifiers(routeModifiers)\n .build();\n\n// Use the builder to create a SearchByTextRequest object and pass the routing parameters.\n// Set setRoutingSummariesIncluded to true.\nfinal SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder(\"Spicy Vegetarian Food in Sydney, Australia\", placeFields)\n .setMaxResultCount(10)\n .setRoutingParameters(routingParameters)\n .setRoutingSummariesIncluded(true)\n .build();\n\n// Call PlacesClient.searchByText() to perform the search.\n// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.\nplacesClient.searchByText(searchByTextRequest) \n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n List\u003cRoutingSummary\u003e routingSummaries = result.getRoutingSummaries();\n List\u003cLeg\u003e legs = routingSummaries.get(0).getLegs();\n Duration duration = legs.get(0).getDuration();\n });\n```"]]