Text Search (New)

Select platform: Android iOS JavaScript Web Service

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.

The service is especially useful for making ambiguous address queries in an automated system, and non-address components of the string may match businesses as well as addresses. Examples of ambiguous address queries are poorly-formatted addresses or requests that include non-address components such as business names. Requests like the first two examples might return zero results unless a location — such as region, location restriction, or location bias — is set.

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.

"10 High Street, UK" or "123 Main Street, US" Multiple "High Street"s in the UK; multiple "Main Street"s in the US. Query doesn't return desirable results unless a location restriction is set.
"ChainRestaurant New York" Multiple "ChainRestaurant" locations in New York; no street address or even street name.
"10 High Street, Escher UK" or "123 Main Street, Pleasanton US" Only one "High Street" in the UK city of Escher; only one "Main Street" in the US city of Pleasanton CA.
"UniqueRestaurantName New York" Only one establishment with this name in New York; no street address needed to differentiate.
"pizza restaurants in New York" This query contains its location restriction, and "pizza restaurants" is a well-defined place type. It returns multiple results.
"+1 514-670-8700"

This query contains a phone number. It returns multiple results for places associated with that phone number.

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.ID and Place.Field.DISPLAY_NAME. That means the Place objects in the response that represent each matching place only contain those two fields.

  • Use SearchByTextRequest.Builder to create a SearchByTextRequest object 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 OnSuccessListener and get the matching places from the SearchByTextResponse object.

Text Search responses

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.

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 list

    Specify which place data fields to return. Pass a list of Place.Field values 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 (ID Only) SKU:

      Place.Field.DISPLAY_NAME, Place.Field.ID, Place.Field.RESOURCE_NAME
    • The following fields trigger the Text Search (Basic) SKU:

      Place.Field.ACCESSIBILITY_OPTIONS, Place.Field.ADDRESS_COMPONENTS, Place.Field.ADR_FORMAT_ADDRESS, Place.Field.BUSINESS_STATUS, Place.Field.FORMATTED_ADDRESS, Place.Field.GOOGLE_MAPS_URI, Place.Field.ICON_BACKGROUND_COLOR, Place.Field.ICON_MASK_URL, Place.Field.LOCATION, 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 (Advanced) SKU:

      Place.Field.CURRENT_OPENING_HOURS, Place.Field.CURRENT_SECONDARY_OPENING_HOURS Place.Field.INTERNATIONAL_PHONE_NUMBER, 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 Place.Field.WEBSITE_URI
    • The following fields trigger the Text Search (Preferred) 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 the SearchByTextRequest object.

  • 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 setTextQuery() method when building the SearchByTextRequest object.

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 SearchByTextRequest object.

  • 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 and high.longitude = 180 degrees, the viewport includes all longitudes.
      • If low.longitude = 180 degrees and high.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 SearchByTextRequest object.

  • 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 SearchByTextRequest object.

  • 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 the SearchByTextRequest object.

  • 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 SearchByTextRequest object.

  • 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 SearchByTextRequest object.

  • 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.

    To set the price levels parameter, call the setPriceLevels() method when building the SearchByTextRequest object.

  • 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 to SearchByTextRequest.RankPreference.RELEVANCE or SearchByTextRequest.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 SearchByTextRequest object.

  • 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 SearchByTextRequest object.

  • 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 SearchByTextRequest object.