Text Search (New) Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
Google Maps Places API Text Search finds places using text queries, handling imprecise addresses and finding businesses by name or type.
Text Search supports various parameters to refine searches, like location restrictions, price levels, and open hours filters.
Search results are ranked by relevance or distance, depending on the query and parameters used.
Requests specify desired data fields, affecting billing based on the selected information.
This feature is part of the Places SDK for Android (New), and developers should be aware of version differences and billing considerations.
Text Search (New) returns information about a set of places based on astring (for example, "pizza in New York" or "shoe stores near Ottawa" or "123Main Street"). The service responds with a list of places matching the textstring and any location bias that has been set.
In addition torequired parameters,Text Search (New) supports refining queries usingoptionalparameters for better results.
Text Search (New) is similar toNearby Search(New). The maindifference between the two is that Text Search (New)lets you specify an arbitrary search string while Nearby Search (New) requires aspecific area in which to search.
Note: Text Search (New) is available in Places SDK forAndroid version 3.3.0 and later. For more information, seeChoose your SDKversion. For moreinformation about using the Kotlin APIs added in version4.0.0, see theReferenceOverview.Text Search requests
Note: Text Search is part ofPlaces SDK for Android (New) and is not available inPlaces SDK for Android.A Text Search request is in the form:
// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.DISPLAY_NAME);// Define latitude and longitude coordinates of the search area.LatLngsouthWest=newLatLng(37.38816277477739,-122.08813770258874);LatLngnorthEast=newLatLng(37.39580487866437,-122.07702325966572);// Use the builder to create a SearchByTextRequest object.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food",placeFields).setMaxResultCount(10).setLocationRestriction(RectangularBounds.newInstance(southWest,northEast)).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();});
In this example, you:
Set the field list to include only
Place.Field.IDandPlace.Field.DISPLAY_NAME. That means thePlaceobjects in the responsethat represent each matching place only contain those two fields.Use
SearchByTextRequest.Builderto create aSearchByTextRequestobject that defines the search.Set the text query string to "Spicy Vegetarian Food".
Set the maximum number of result places to 10. The default and themaximum is 20.
Restrict the search area to the rectangle defined by latitude andlongitude coordinates. No matches outside of this area are returned.
Add an
OnSuccessListenerand get the matching places from theSearchByTextResponseobject.
PlacesClient, seeInitialize the Places API client.You can use aCancellationTokento attempt to cancel a request to any of the request classes (for example,FetchPlaceRequest). Cancellation is done on a best-effort basis.Once a cancellation request is issued, no response will be returned.Issuing a cancellation token does NOT guarantee that a particular requestwill be cancelled, and you may still be charged for the request even if noresponse is returned.
Text Search responses
TheSearchByTextResponseclass represents the response from a search request. ASearchByTextResponseobject contains:
A list of
Placeobjects that represent all matching places, with onePlaceobject per matching place.Each
Placeobject only contains the fields defined by the field listpassed in the request.
For example, in the request you defined a field list as:
// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.DISPLAY_NAME);
This field list means that eachPlace object in the response contains only theplace ID and name of each matching place. You can then use thePlace.getId()andPlace.getName() methods to access these fields in eachPlace object.
For more examples of accessing data in aPlace object, seeAccess Placeobject data fields
Pagination
Text Search'sSearchByTextResponse class provides access to text search result pagination through itsgetPagination() method, which returns a Pagination object.
Use the Pagination object'shasNextPage() method to determine if additional pages of results are available. This method returns a boolean value (true or false).
WhilehasNextPage() returns true, call thefetchNextPage() method to retrieve the next page of results.
The following example shows how to check if a next page is available, and thenload the page.
Kotlin
valsearchByTextRequest=searchByTextRequest("restaurants",Arrays.asList(Place.Field.NAME)){maxResultCount=10}// using pagination object (Preferred)placesClient.searchByText(searchByTextRequest).addOnSuccessListener{response:SearchByTextResponse->valplaces=response.placesvalpagination=response.paginationif(pagination.hasNextPage()){pagination.setPageSize(20)pagination.fetchNextPage().addOnSuccessListener{nextPageResponse->valnextPagePlaces=nextPageResponse.getPlaces()}.addOnFailureListener{// Handle error with given status code}}}.addOnFailureListener{// TODO: Handle error with given status code.exception->{exception.printStackTrace();}}
Java
SearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("restaurants",Arrays.asList(Place.Field.NAME)).setMaxResultCount(10).build();// using pagination object (Preferred)placesClient.searchByText(searchByTextRequest).addOnSuccessListener((response)->{List<Place>places=response.getPlaces();Log.i(TAG,"Places result: "+places);Paginationpagination=response.getPagination();if(pagination.hasNextPage()){pagination.setPageSize(20);// change the page size from 10 to 20pagination.fetchNextPage().addOnSuccessListener((nextPageResponse)->{List<Place>nextPagePlaces=nextPageResponse.getPlaces();Log.i(TAG,"Next page places result: "+nextPagePlaces);});}}).addOnFailureListener((exception)->{if(exceptioninstanceofApiException){// Handle error with given status code}});
Required parameters
The required parameters forSearchByTextRequestare:
Field list
Specify which place data fields to return. Pass a list of
Place.Fieldvalues specifying the data fields to return. There is no default list of returned fields in the response.Field lists are a good design practice to ensure that you don't request unnecessary data, which helps to avoid unnecessary processing time and billing charges.
Specify one or more of the following fields:
The following fields trigger theText Search Essentials ID Only SKU:
Place.Field.DISPLAY_NAME*
* Use instead ofPlace.Field.NAME(deprecated in version 4.0).Place.Field.IDPlace.Field.RESOURCE_NAME*
* Contains the place resource name in the form:places/PLACE_ID.
UseDISPLAY_NAMEto access the text name of the place.The following fields trigger theText Search Pro SKU:
Place.Field.ACCESSIBILITY_OPTIONS*
Use instead ofPlace.Field.WHEELCHAIR_ACCESSIBLE_ENTRANCE(deprecated).Place.Field.ADDRESS_COMPONENTSPlace.Field.ADR_FORMAT_ADDRESSPlace.Field.BUSINESS_STATUSPlace.Field.FORMATTED_ADDRESS*
Use instead ofPlace.Field.ADDRESS(deprecated).Place.Field.GOOGLE_MAPS_URIPlace.Field.ICON_BACKGROUND_COLORPlace.Field.ICON_MASK_URL*
Use instead ofPlace.Field.ICON_URL(deprecated).Place.Field.LOCATION*
Use instead ofPlace.Field.LAT_LNG(deprecated).Place.Field.PHOTO_METADATASPlace.Field.PLUS_CODEPlace.Field.PRIMARY_TYPEPlace.Field.PRIMARY_TYPE_DISPLAY_NAMEPlace.Field.SHORT_FORMATTED_ADDRESSPlace.Field.SUB_DESTINATIONSPlace.Field.TYPESPlace.Field.UTC_OFFSETPlace.Field.VIEWPORTThe following fields trigger theText Search Enterprise SKU:
Place.Field.CURRENT_OPENING_HOURSPlace.Field.CURRENT_SECONDARY_OPENING_HOURSPlace.Field.INTERNATIONAL_PHONE_NUMBER*
* Use instead ofPlace.Field.PHONE_NUMBER, which isdeprecated.Place.Field.NATIONAL_PHONE_NUMBERPlace.Field.OPENING_HOURSPlace.Field.PRICE_LEVELPlace.Field.RATINGPlace.Field.SECONDARY_OPENING_HOURSPlace.Field.USER_RATING_COUNT*
* Use instead ofPlace.Field.USER_RATINGS_TOTAL, which isdeprecated.Place.Field.WEBSITE_URIThe following fields trigger theText Search Enterprise Plus SKU:
Place.Field.ALLOWS_DOGSPlace.Field.CURBSIDE_PICKUPPlace.Field.DELIVERYPlace.Field.DINE_INPlace.Field.EDITORIAL_SUMMARYPlace.Field.EV_CHARGE_OPTIONSPlace.Field.FUEL_OPTIONSPlace.Field.GOOD_FOR_CHILDRENPlace.Field.GOOD_FOR_GROUPSPlace.Field.GOOD_FOR_WATCHING_SPORTSPlace.Field.LIVE_MUSICPlace.Field.MENU_FOR_CHILDRENPlace.Field.OUTDOOR_SEATINGPlace.Field.PARKING_OPTIONSPlace.Field.PAYMENT_OPTIONSPlace.Field.RESERVABLEPlace.Field.RESTROOMPlace.Field.REVIEWSPlace.Field.SERVES_BEERPlace.Field.SERVES_BREAKFASTPlace.Field.SERVES_BRUNCHPlace.Field.SERVES_COCKTAILSPlace.Field.SERVES_COFFEEPlace.Field.SERVES_DESSERTPlace.Field.SERVES_DINNERPlace.Field.SERVES_LUNCHPlace.Field.SERVES_VEGETARIAN_FOODPlace.Field.SERVES_WINEPlace.Field.TAKEOUT
To set the field list parameter, call the
setPlaceFields()method when building theSearchByTextRequestobject.Text query
The text string on which to search, for example: "restaurant", "123 Main Street", or "best place to visit in San Francisco". The API returns candidate matches based on this string and orders the results based on their perceived relevance.
To set the text query parameter, call the
Note:For best results when searching on a phone number,include the country code followed by a space, and set thesetTextQuery()method when building theSearchByTextRequestobject.regionCodeparameter to correspond to the country code.Phone number formats vary by country and the API attempts to return a result for thesedifferent formats.
Optional parameters
Use theSearchByTextRequestobject to specify the optional parameters for your request.
Included type
Restricts the results to places matching the specified type defined byTable A. Only one type may be specified. For example:
setIncludedType("bar")setIncludedType("pharmacy")
To set the included type parameter, call the
setIncludedType()method when building theSearchByTextRequestobject.Location bias
Specifies an area to search. This location serves as a bias which means results around the specified location can be returned, including results outside the specified area.
You can specify location restriction or location bias, but not both. Think of location restriction as specifying the region which the results must be within, and location bias as specifying the region that the results will likely be within or near — keeping in mind that when using location bias, results can still be outside of the specified area.
Note:If you omit both location bias and location restriction, then the API uses IP biasing by default. With IP biasing, the API uses the IP address of the device to bias the results.Note: ThelocationBiasparameter can be overridden if thetextQuerycontains an explicit location such asMarket in Barcelona. In this case,locationBiasis ignored.Specify the region as a rectangular Viewport or as a circle.
A circle is defined by center point and radius in meters. The radius must be between 0.0 and 50000.0, inclusive. For example:
// Define latitude and longitude coordinates of the center of the search area.LatLngsearchCenter=newLatLng(37.38816277477739,-122.08813770258874);// Use the builder to create a SearchByTextRequest object.// Set the radius of the search area to 500.0 meters.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food",placeFields).setMaxResultCount(10).setLocationBias(CircularBounds.newInstance(searchCenter,500.0)).build();
A rectangle is a latitude-longitude viewport, represented as two diagonally opposite low and high points. The low point marks the southwest corner of the rectangle, and the high point represents the northeast corner of the rectangle.
A viewport is considered a closed region, meaning it includes its boundary. The latitude bounds must range between -90 to 90 degrees inclusive, and the longitude bounds must range between -180 to 180 degrees inclusive:
- If
low=high, the viewport consists of that single point. - If
low.longitude>high.longitude, the longitude range is inverted (the viewport crosses the 180 degree longitude line). - If
low.longitude= -180 degrees andhigh.longitude= 180 degrees, the viewport includes all longitudes. - If
low.longitude= 180 degrees andhigh.longitude= -180 degrees, the longitude range is empty. - If
low.latitude>high.latitude, the latitude range is empty.
Both low and high must be populated, and the represented box cannot be empty. An empty viewport results in an error.
For example, of a rectangular viewport seeText Search requests.
To set the location bias parameter, call the
setLocationBias()method when building theSearchByTextRequestobject.- If
Location restriction
Specifies an area to search. Results outside the specified area are not returned. Specify the region as a rectangular Viewport. See the description ofLocation bias for information on defining the Viewport.
You can specify location restriction or location bias, but not both. Think of location restriction as specifying the region which the results must be within, and location bias as specifying the region that the results must be near but can be outside the area.
Note:If you omit both location bias and location restriction, then the API uses IP biasing by default. With IP biasing, the API uses the IP address of the device to bias the results.To set the location restriction parameter, call the
setLocationRestriction()method when building theSearchByTextRequestobject.Maximum result count
Specifies the maximum number of place results to return. Must be between 1 and 20 (default) inclusive.
To set the maximum result count parameter, call the
setMaxResultCount()method when building theSearchByTextRequestobject.Minimum rating
Restricts results to only those whose average user rating is greater than or equal to this limit. Values must be between 0.0 and 5.0 (inclusive) in increments of 0.5. For example: 0, 0.5, 1.0, ... , 5.0 inclusive. Values are rounded up to the nearest 0.5. For example, a value of 0.6 eliminates all results with a rating less than 1.0.
To set the minimum rating parameter, call the
setMinRating()method when building theSearchByTextRequestobject.Open now
If
true, return only those places that are open for business at the time the query is sent. Iffalse, return all businesses regardless of open status. Places that don't specify opening hours in the Google Places database are returned if you set this parameter tofalse.To set the open now parameter, call the
setOpenNow()method when building theSearchByTextRequestobject.Price levels
By default, results include places that provide services at all price levels. To restrict results to only include places at particular price levels, you can pass a list of integer values that correspond to the price levels for the places that you want to return:
1- Place provides inexpensive services.2- Place provides moderately priced services.3- Place provides expensive services.4- Place provides very expensive services.
0, which indicates that the place provides free services, may be included in a response, but cannot be used as a filter value in a request.To set the price levels parameter, call the
setPriceLevels()method when building theSearchByTextRequestobject.Rank preference
Specifies how the results are ranked in the response based on the type of query:
- For a categorical query such as "Restaurants in New York City",
SearchByTextRequest.RankPreference.RELEVANCE(rank results by search relevance) is the default. You can set rank preference toSearchByTextRequest.RankPreference.RELEVANCEorSearchByTextRequest.RankPreference.DISTANCE(rank results by distance). - For a non-categorical query such as "Mountain View, CA", we recommend that you leave the rank preference parameter unset.
To set the rank preference parameter, call the
setRankPreference()method when building theSearchByTextRequestobject.- For a categorical query such as "Restaurants in New York City",
Region code
The region code used to format the response, specified as a two-character CLDR code value. This parameter can also have a bias effect on the search results. There is no default value.
If the country name of the address field in the response matches the region code, the country code is omitted from address.
Most CLDR codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). The parameter can affect results based on applicable law.
To set the region code parameter, call the
setRegionCode()method when building theSearchByTextRequestobject.Strict type filtering
Used with the include type parameter. When set to
true, only places that match the specified types specified by include type are returned. Whenfalse, the default, the response can contain places that don't match the specified types.To set the strict type filtering parameter, call the
setStrictTypeFiltering()method when building theSearchByTextRequestobject.
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.