Place Search

Place Search introduces Text Search (New), which takes a text query and returns a set of places.

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. Text Search (New) lets you search for places by type, filter using criteria such as business hours and rating, and restrict or bias results to a specific location. Text Search (New) is built completely new, and offers improved performance and data quality over legacy Places APIs.

Prerequisites

To use Text Search (New), you must enable "Places API (New)" on your Google Cloud project. See Get started for details.

Text search highlights

Text Search (New) has the following improvements:

  • Additional search filters, featuring many new place types as well as the ability to filter by minimum rating.
  • Field masking is now supported.
  • Place fields now includes ratings and reviews.

Find places by text query

Call searchByText to return a list of places from a text query or phone number. If the query contains a phone number, the region parameter should be set to the same region as that of the requesting domain. For example, if you use a phone number to search for a place in Japan, and the requesting domain is jp, you must set the region parameter to 'jp'. If region is omitted from the request, the API will default to the United States ('us') region.

Use the fields parameter to specify a comma-separated list of one or more data fields in camel case.

The following example shows calling searchByText to find places by text query.

TypeScript

let map;
let center;

async function initMap() {
    const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;

    center = {lat: 37.4161493, lng: -122.0812166};
    map = new Map(document.getElementById('map') as HTMLElement, {
        center: center,
        zoom: 14,
        // ...
    });

    findPlaces();
}

async function findPlaces() {
    const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
    //@ts-ignore
    const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
    const request = {
        textQuery: 'Tacos in Mountain View',
        fields: ['displayName', 'location', 'businessStatus'],
        includedType: 'restaurant',
        isOpenNow: true,
        language: 'en-US',
        maxResultCount: 7,
        minRating: 3.2,
        region: 'us',
        useStrictTypeFiltering: false,
    };

    //@ts-ignore
    const { places } = await Place.searchByText(request);

    if (places.length) {
        console.log(places);

        const { LatLngBounds } = await google.maps.importLibrary("core") as google.maps.CoreLibrary;
        const bounds = new LatLngBounds();

        // Loop through and get all the results.
        places.forEach((place) => {
            const markerView = new AdvancedMarkerElement({
                map,
                position: place.location,
                title: place.displayName,
            });

            bounds.extend(place.location);
            console.log(place);
        });

        map.setCenter(bounds.getCenter());

    } else {
        console.log('No results');
    }
}

initMap();

JavaScript

let map;
let center;

async function initMap() {
  const { Map } = await google.maps.importLibrary("maps");

  center = { lat: 37.4161493, lng: -122.0812166 };
  map = new Map(document.getElementById("map"), {
    center: center,
    zoom: 14,
    // ...
  });
  findPlaces();
}

async function findPlaces() {
  const { Place } = await google.maps.importLibrary("places");
  //@ts-ignore
  const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
  const request = {
    textQuery: "Tacos in Mountain View",
    fields: ["displayName", "location", "businessStatus"],
    includedType: "restaurant",
    isOpenNow: true,
    language: "en-US",
    maxResultCount: 7,
    minRating: 3.2,
    region: "us",
    useStrictTypeFiltering: false,
  };
  //@ts-ignore
  const { places } = await Place.searchByText(request);

  if (places.length) {
    console.log(places);

    const { LatLngBounds } = await google.maps.importLibrary("core");
    const bounds = new LatLngBounds();

    // Loop through and get all the results.
    places.forEach((place) => {
      const markerView = new AdvancedMarkerElement({
        map,
        position: place.location,
        title: place.displayName,
      });

      bounds.extend(place.location);
      console.log(place);
    });
    map.setCenter(bounds.getCenter());
  } else {
    console.log("No results");
  }
}

initMap();