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 a string (for example, "pizza in New York" or "shoe stores near Ottawa" or "123 Main Street"). The service responds with a list of places matching the text string and any location bias that has been set.
In addition to required parameters, Text Search (New) supports refining queries using optional parameters for better results.
Text Search (New) is similar to Nearby Search (New). The main difference between the two is that Text Search (New) lets you specify an arbitrary search string while Nearby Search (New) requires a specific area in which to search.
Text Search requests
A Text Search request is in the form:
// Specify the list of fields to return. final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.DISPLAY_NAME); // Define latitude and longitude coordinates of the search area. LatLng southWest = new LatLng(37.38816277477739, -122.08813770258874); LatLng northEast = new LatLng(37.39580487866437, -122.07702325966572); // Use the builder to create a SearchByTextRequest object. final SearchByTextRequest searchByTextRequest = 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.IDand- Place.Field.DISPLAY_NAME. That means the- Placeobjects in the response that represent each matching place only contain those two fields.
- Use - SearchByTextRequest.Builderto create a- SearchByTextRequestobject 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 the maximum is 20. 
- Restrict the search area to the rectangle defined by latitude and longitude coordinates. No matches outside of this area are returned. 
 
- Add an - OnSuccessListenerand get the matching places from the- SearchByTextResponseobject.
Text Search responses
The
SearchByTextResponse
class represents the response from a search request. A SearchByTextResponse
object contains:
- A list of - Placeobjects that represent all matching places, with one- Placeobject per matching place.
- Each - Placeobject only contains the fields defined by the field list passed in the request.
For example, in the request you defined a field list as:
// Specify the list of fields to return. final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.DISPLAY_NAME);
This field list means that each Place object in the response contains only the
place ID and name of each matching place. You can then use the Place.getId()
and Place.getName() methods to access these fields in each Place object.
For more examples of accessing data in a Place object, see Access Place
object data fields
Required parameters
The required parameters for
SearchByTextRequest
are:
- 
    Field listSpecify 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 the Text Search Essentials ID Only SKU: - Place.Field.DISPLAY_NAME*
 * Use instead of- Place.Field.NAME(deprecated in version 4.0).
 - Place.Field.ID
 - Place.Field.RESOURCE_NAME*
 * Contains the place resource name in the form:- places/PLACE_ID.
 Use- DISPLAY_NAMEto access the text name of the place.
- The following fields trigger the Text Search Pro SKU: - Place.Field.ACCESSIBILITY_OPTIONS*
 Use instead of- Place.Field.WHEELCHAIR_ACCESSIBLE_ENTRANCE(deprecated).
 - Place.Field.ADDRESS_COMPONENTS
 - Place.Field.ADR_FORMAT_ADDRESS
 - Place.Field.BUSINESS_STATUS
 - Place.Field.FORMATTED_ADDRESS*
 Use instead of- Place.Field.ADDRESS(deprecated).
 - Place.Field.GOOGLE_MAPS_URI
 - Place.Field.ICON_BACKGROUND_COLOR
 - Place.Field.ICON_MASK_URL*
 Use instead of- Place.Field.ICON_URL(deprecated).
 - Place.Field.LOCATION*
 Use instead of- Place.Field.LAT_LNG(deprecated).
 - Place.Field.PHOTO_METADATAS
 - Place.Field.PLUS_CODE
 - Place.Field.PRIMARY_TYPE
 - Place.Field.PRIMARY_TYPE_DISPLAY_NAME
 - Place.Field.SHORT_FORMATTED_ADDRESS
 - Place.Field.SUB_DESTINATIONS
 - Place.Field.TYPES
 - Place.Field.UTC_OFFSET
 - Place.Field.VIEWPORT
- The following fields trigger the Text Search Enterprise SKU: - Place.Field.CURRENT_OPENING_HOURS
 - Place.Field.CURRENT_SECONDARY_OPENING_HOURS
 - Place.Field.INTERNATIONAL_PHONE_NUMBER*
 * Use instead of- Place.Field.PHONE_NUMBER, which is deprecated.
 - Place.Field.NATIONAL_PHONE_NUMBER
 - Place.Field.OPENING_HOURS
 - Place.Field.PRICE_LEVEL
 - Place.Field.RATING
 - Place.Field.SECONDARY_OPENING_HOURS
 - Place.Field.USER_RATING_COUNT*
 * Use instead of- Place.Field.USER_RATINGS_TOTAL, which is deprecated.
 - Place.Field.WEBSITE_URI
- The following fields trigger the Text Search Enterprise Plus SKU: - Place.Field.ALLOWS_DOGS
 - Place.Field.CURBSIDE_PICKUP
 - Place.Field.DELIVERY
 - Place.Field.DINE_IN
 - Place.Field.EDITORIAL_SUMMARY
 - Place.Field.EV_CHARGE_OPTIONS
 - Place.Field.FUEL_OPTIONS
 - Place.Field.GOOD_FOR_CHILDREN
 - Place.Field.GOOD_FOR_GROUPS
 - Place.Field.GOOD_FOR_WATCHING_SPORTS
 - Place.Field.LIVE_MUSIC
 - Place.Field.MENU_FOR_CHILDREN
 - Place.Field.OUTDOOR_SEATING
 - Place.Field.PARKING_OPTIONS
 - Place.Field.PAYMENT_OPTIONS
 - Place.Field.RESERVABLE
 - Place.Field.RESTROOM
 - Place.Field.REVIEWS
 - Place.Field.SERVES_BEER
 - Place.Field.SERVES_BREAKFAST
 - Place.Field.SERVES_BRUNCH
 - Place.Field.SERVES_COCKTAILS
 - Place.Field.SERVES_COFFEE
 - Place.Field.SERVES_DESSERT
 - Place.Field.SERVES_DINNER
 - Place.Field.SERVES_LUNCH
 - Place.Field.SERVES_VEGETARIAN_FOOD
 - Place.Field.SERVES_WINE
 - Place.Field.TAKEOUT
 To set the field list parameter, call the setPlaceFields()method when building theSearchByTextRequestobject.
- 
    Text queryThe 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 setTextQuery()method when building theSearchByTextRequestobject.
Optional parameters
Use the
SearchByTextRequest
object to specify the optional parameters for your request.
- Included type- Restricts the results to places matching the specified type defined by Table 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 the- SearchByTextRequestobject.
- 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. - 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. LatLng searchCenter = new LatLng(37.38816277477739, -122.08813770258874); // Use the builder to create a SearchByTextRequest object. // Set the radius of the search area to 500.0 meters. final SearchByTextRequest searchByTextRequest = 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 see Text Search requests. - To set the location bias parameter, call the - setLocationBias()method when building the- SearchByTextRequestobject.
- 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 of Location 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. - To set the location restriction parameter, call the - setLocationRestriction()method when building the- SearchByTextRequestobject.
- 
    Maximum result countSpecifies 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 the- SearchByTextRequestobject.
- Open now- If - true, return only those places that are open for business at the time the query is sent. If- false, 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 to- false.- To set the open now parameter, call the - setOpenNow()method when building the- SearchByTextRequestobject.
- 
    Price levelsBy 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.
 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 the- SearchByTextRequestobject.
- 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 the- SearchByTextRequestobject.
- 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. When- false, 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 the- SearchByTextRequestobject.