Examples

This section covers a series of example requests to the Places Insights API.

To use computeInsights, submit an HTTP POST request in the following form:

https://areainsights.googleapis.com/v1:computeInsights

Return places within a circle

Return all restaurants within a 200m radius of Trafalgar Square, London.

  • The search area is a circle centered on a specific latitude and longitude. The radius of this circle is 200 meters, which determines the size of the search area.
  • The place type requested is restaurant, and this is passed using included_types within type_filters.
  • The count is requested using INSIGHTS_COUNT, and the place IDs are requested using INSIGHTS_PLACES.
{
  "insights": ["INSIGHT_COUNT", "INSIGHT_PLACES"],
  "filter": {
    "location_filter": {
      "circle": {
        "lat_lng": { "latitude": 51.508, "longitude": -0.128},
        "radius": 200
      }
    },
    "type_filter": { "included_types": "restaurant" }
  }
}

Exclude place types

You can also exclude place types from the count.

The following request is the same as the first example, but adds excluded_types to the type_filters. You can use either a string or an array of strings for the included_types and excluded_types.

This example excludes two place types: cafe and bakery, from the restaurant count.

{
    "insights": ["INSIGHT_COUNT", "INSIGHT_PLACES"],
    "filter": {
        "location_filter": {
            "circle": {
                "lat_lng": { "latitude": 51.508, "longitude": -0.128},
                "radius": 200
            }
        },
        "type_filter": {
            "included_types": "restaurant",
            "excluded_types": [
                "cafe",
                "bakery"
            ]
        }
    }
}

Use primary type

This example modifies the request from the first example to include only places that have a primaryType of restaurant in the count.

{
  "insights": ["INSIGHT_COUNT", "INSIGHT_PLACES"],
  "filter": {
    "location_filter": {
      "circle": {
        "lat_lng": { "latitude": 51.508, "longitude": -0.128},
        "radius": 200
      }
    },
    "type_filter": { "included_primary_types": "restaurant" }
  }
}

Custom polygon

This example demonstrates how to use a custom polygon to define your search area. Keep in mind that specifying INSIGHTS_PLACES restricts the search to areas small enough to return up to 100 place IDs. For larger areas, use INSIGHTS_COUNT to bypass this limitation so that the service won't need to return individual place IDs.

As before, the place type used is restaurant. This example also introduces three other filters:

  • operating_status: This example counts only operational places.
  • price_level: This example counts only inexpensive and moderately priced places.
  • rating_filter: This example counts only places with a review score between 4.0 and 5.0.
{
    "insights": [ "INSIGHT_COUNT" ],
    "filter": {
        "location_filter": {
            "custom_area": {
                "polygon": {
                    "coordinates": [
                        { "latitude": 37.776, "longitude": -122.666 },
                        { "latitude": 37.130, "longitude": -121.898 },
                        { "latitude": 37.326, "longitude": -121.598 },
                        { "latitude": 37.912, "longitude": -122.247 },
                        { "latitude": 37.776, "longitude": -122.666 }
                    ]
                }
            }
        },
        "type_filter": {
            "included_types": "restaurant"
        },
        "operating_status": [ "OPERATING_STATUS_OPERATIONAL" ],
        "price_levels": [ "PRICE_LEVEL_INEXPENSIVE", "PRICE_LEVEL_MODERATE" ],
        "rating_filter": { "min_rating": 4.0, "max_rating": 5.0 }
    }
}

Geographical area

This example uses a Geographical Area place ID to set the search area. These place IDs include the geometry of a place, such as a town or city. The place ID used here is ChIJiQHsW0m3j4ARm69rRkrUF3w, which corresponds to the city of Mountain View, California.

Passing the place ID to the Places Insights API sets the search area to the bounds of the geographic area. The place ID is passed using place, in the format places/<place_ID>.

You can obtain a Geographical Area place ID in any of the following ways:

{
    "insights": [
        "INSIGHT_COUNT"
    ],
    "filter": {
        "location_filter": {
            "region": {
                "place": "places/ChIJiQHsW0m3j4ARm69rRkrUF3w"
            }
        },
        "type_filter": {
            "included_types": [
                "restaurant"
            ]
        }
    }
}