PLACES_COUNT_PER_TYPE function

The PLACES_COUNT_PER_TYPE function returns a table of counts for each place type specified to the function. For example, if you search for the types doctor, hospital, and pharmacy the response contains a table with a separate row for each type.

Because the PLACES_COUNT_PER_TYPE function returns a table, call it using a FROM clause.

  • Input parameters:

    • Required: The geography filter parameter that specifies the search area. The geography parameter takes a value defined by the BigQuery GEOGRAPHY data type, which supports points, linestrings, and polygons.

      For examples of using different types of search geographies, such as viewports and lines, see PLACES_COUNT function.

    • Required: The types filter parameter that specifies the place types to search for.

    • Optional: Additional filter parameters to refine your search.

  • Returns:

    • A table with one row per types value. The table contains the columns type (STRING), count (INT64), and sample_place_ids (ARRAY<STRING>) where sample_place_ids contains up to 250 place IDs for each type.

Example: Return count of restaurant, cafes, and bars

In this example, you search for all operational restaurant, cafe, and bars in the specified search area defined as a polygon in New York City.

The types parameter takes an array of STRING values specifying the place types to search for. For the complete list of possible values, see Place types.

This example also uses the BigQuery ST_GEOGFROMTEXT function to return a GEOGRAPHY value from a polygon.

DECLARE geo GEOGRAPHY;
SET geo = ST_GEOGFROMTEXT('''POLYGON((-73.985708 40.75773,-73.993324 40.750298,
                                      -73.9857 40.7484,-73.9785 40.7575,
                                      -73.985708 40.75773))''');  -- NYC viewport

SELECT * FROM `places_insights___us___sample.PLACES_COUNT_PER_TYPE`(
  JSON_OBJECT(
      'types', ["restaurant", "cafe", "bar"],
      'geography', geo,
      'business_status', ['OPERATIONAL']
      )
);

This function returns a table with three rows, one per type:

Results for Place Count Type function in New York City.