Place Search (Preview)

Place Search (Preview) introduces Text Search (Preview), which takes a text query and returns a set of places, and Find Place (Preview), which returns a single place based on a text query or phone number.

Text Search (Preview) 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 (Preview) 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 (Preview) is built completely new, and offers improved performance and data quality over legacy Places APIs.

Prerequisites

Welcome to the Text Search (Preview). While in preview this API is free of charge. To use Text Search (Preview), you must enable "Places API (New)" on your Google Cloud project. See Get started for details.

Text search highlights

Text Search (Preview) 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;
    const { LatLng, LatLngBounds } = await google.maps.importLibrary("core") as google.maps.CoreLibrary;

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

    findPlaces(LatLng, LatLngBounds);
}

async function findPlaces(LatLng, LatLngBounds) {
    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 = {
        query: 'Tacos in Mountain View',
        fields: ['displayName', 'location', 'businessStatus', 'hasWheelchairAccessibleEntrance'],
        includedType: 'restaurant',
        isOpenNow: true,
        language: 'en-US',
        maxResultCount: 7,
        minRating: 3.2,
        region: 'us',
        useStrictTypeFiltering: false,
    };

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

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

            bound.extend(new LatLng(place.location));
            console.log(place);
        });

        map.setCenter(bound.getCenter());

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

initMap();

JavaScript

let map;
let center;

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

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

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

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

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

initMap();

Find place (Preview)

Find Place (Preview) takes a text query or phone number, and returns a single result. The Find Place (Preview) method is billed, see Usage and billing for details.

Find a place by text query

Call findPlaceFromQuery to find a place by text query. Use the fields parameter to specify a comma-separated list of one or more data fields in camel case.

The following example shows using an async/await pattern to call findPlaceFromQuery and display the results on a map.

TypeScript

let map: google.maps.Map;
let centerCoordinates = { lat: 37.4161493, lng: -122.0812166 };

async function initMap() {
    const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
    const { Place } =  await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
    const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;

    map = new Map(document.getElementById('map') as HTMLElement, {
        center: centerCoordinates,
        zoom: 14,
        // ...
    });

    findPlace(AdvancedMarkerElement, Place);
    getPlaceDetails(Place);
}

async function findPlace(AdvancedMarkerElement, Place) {
    const request = {
        query: 'Sports Page',
        fields: ['displayName', 'location'],
        locationBias: centerCoordinates,
    };

    const { places } = await Place.findPlaceFromQuery(request);

    if (places.length) {
        const place = places[0];
        const location = place.location as google.maps.LatLng;
        const markerView = new AdvancedMarkerElement({
            map,
            position: place.location,
            title: place.displayName,
        });
        map.setCenter(location);

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

JavaScript

let map;
let centerCoordinates = { lat: 37.4161493, lng: -122.0812166 };

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

  map = new Map(document.getElementById("map"), {
    center: centerCoordinates,
    zoom: 14,
    // ...
  });
  findPlace(AdvancedMarkerElement, Place);
  getPlaceDetails(Place);
}

async function findPlace(AdvancedMarkerElement, Place) {
  const request = {
    query: "Sports Page",
    fields: ["displayName", "location"],
    locationBias: centerCoordinates,
  };
  const { places } = await Place.findPlaceFromQuery(request);

  if (places.length) {
    const place = places[0];
    const location = place.location;
    const markerView = new AdvancedMarkerElement({
      map,
      position: place.location,
      title: place.displayName,
    });

    map.setCenter(location);
  } else {
    console.log("No results");
  }
}

Find a place by phone number

Call findPlaceFromPhoneNumber to find a place by phone number. Phone numbers must be in international format (prefixed by a plus sign ("+"), followed by the country code, then the phone number itself). See E.164 ITU recommendation for more information. Use the fields parameter to specify a comma-separated list of one or more place data fields in camel case.

The following example shows using an async/await pattern to call findPlaceFromPhoneNumber and display the results on a map.

TypeScript

async function findPlaceByPhone(AdvancedMarkerElement, Place) {
    const request = {
        phoneNumber: '+1(206)787-5388',
        fields: ['displayName', 'location'],
    }

    const { places } = await Place.findPlaceFromPhoneNumber(request);

    if (places.length) {
        const place = places[0];
        const markerView = new AdvancedMarkerElement({
            map,
            position: place.location,
            title: place.displayName,
        });
    } else {
        console.log('No results');
    }
}

JavaScript

async function findPlaceByPhone(AdvancedMarkerElement, Place) {
  const request = {
    phoneNumber: "+1(206)787-5388",
    fields: ["displayName", "location"],
  };
  const { places } = await Place.findPlaceFromPhoneNumber(request);

  if (places.length) {
    const place = places[0];
    const markerView = new AdvancedMarkerElement({
      map,
      position: place.location,
      title: place.displayName,
    });
  } else {
    console.log("No results");
  }
}