Examples

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

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 thesearch area.
  • Theplace type requested is restaurant, and this is passed usingincludedTypes withintypeFilters.
  • The count is requested usingINSIGHTS_COUNT, and theplace IDs arerequested usingINSIGHTS_PLACES.

Rest

curl--location'https://areainsights.googleapis.com/v1:computeInsights'\--header'X-Goog-Api-Key:API_KEY'\--header'Content-Type: application/json'\--data'{  "insights": ["INSIGHT_COUNT", "INSIGHT_PLACES"],  "filter": {    "locationFilter": {      "circle": {        "latLng": { "latitude": 51.508, "longitude": -0.128},        "radius": 200      }    },    "typeFilter": { "includedTypes": "restaurant" }  }}'

Python (gRPC)

fromgoogle.mapsimportareainsights_v1fromgoogle.maps.areainsights_v1.typesimport(ComputeInsightsRequest,Filter,LocationFilter,TypeFilter,Insight)fromgoogle.typeimportlatlng_pb2fromgoogle.oauth2importservice_accountdefget_area_insights():# Initialize the clientcredentials=service_account.Credentials.from_service_account_file('path/to/service_account.json',scopes=['https://www.googleapis.com/auth/cloud-platform'])client=areainsights_v1.AreaInsightsClient(credentials=credentials)# Create location filter with circlelat_lng=latlng_pb2.LatLng(latitude=51.508,longitude=-0.128)location_filter=LocationFilter(circle=LocationFilter.Circle(lat_lng=lat_lng,radius=200))# Create type filtertype_filter=TypeFilter(included_types=["restaurant"])# Create the main filterfilter=Filter(location_filter=location_filter,type_filter=type_filter)# Create the requestrequest=ComputeInsightsRequest(insights=[Insight.INSIGHT_COUNT,Insight.INSIGHT_PLACES],filter=filter)try:# Make the requestresponse=client.compute_insights(request=request)# Print resultsprint(f"Total count:{response.count}")print("\nPlaces found:")forplaceinresponse.place_insights:print(f"Place ID:{place.place}")exceptExceptionase:print(f"Error occurred:{e}")if__name__=="__main__":get_area_insights()

Exclude place types

You can exclude place types from the count.

The following request is the same as the first example, but addsexcludedTypes to thetypeFilters. You can use either a string or an arrayof strings for theincludedTypes andexcludedTypes.

This example excludes two place types:cafe andbakery, from therestaurant count.

Rest

curl--location'https://areainsights.googleapis.com/v1:computeInsights'\--header'X-Goog-Api-Key:API_KEY'\--header'Content-Type: application/json'\--data'{    "insights": ["INSIGHT_COUNT", "INSIGHT_PLACES"],    "filter": {        "locationFilter": {            "circle": {                "latLng": { "latitude": 51.508, "longitude": -0.128},                "radius": 200            }        },        "typeFilter": {            "includedTypes": "restaurant",            "excludedTypes": [                "cafe",                "bakery"            ]        }    }}'

Python (gRPC)

fromgoogle.mapsimportareainsights_v1fromgoogle.maps.areainsights_v1.typesimport(ComputeInsightsRequest,Filter,LocationFilter,TypeFilter,Insight)fromgoogle.typeimportlatlng_pb2fromgoogle.oauth2importservice_accountdefget_area_insights():# Initialize the client with service accountcredentials=service_account.Credentials.from_service_account_file('path/to/service_account.json',scopes=['https://www.googleapis.com/auth/cloud-platform'])client=areainsights_v1.AreaInsightsClient(credentials=credentials)# Create location filter with circlelat_lng=latlng_pb2.LatLng(latitude=51.508,longitude=-0.128)location_filter=LocationFilter(circle=LocationFilter.Circle(lat_lng=lat_lng,radius=200))# Create type filter with both included and excluded typestype_filter=TypeFilter(included_types=["restaurant"],excluded_types=["cafe","bakery"])# Create the main filterfilter=Filter(location_filter=location_filter,type_filter=type_filter)# Create the requestrequest=ComputeInsightsRequest(insights=[Insight.INSIGHT_COUNT,Insight.INSIGHT_PLACES],filter=filter)try:# Make the requestresponse=client.compute_insights(request=request)# Print resultsprint(f"Total count:{response.count}")print("\nPlaces found:")forplaceinresponse.place_insights:print(f"Place ID:{place.place}")exceptExceptionase:print(f"Error occurred:{e}")if__name__=="__main__":get_area_insights()

Use primary type

This example modifies the request from the first example to include only placesthat have aprimaryType ofrestaurant in the count.

Rest

curl--location'https://areainsights.googleapis.com/v1:computeInsights'\--header'X-Goog-Api-Key:API_KEY'\--header'Content-Type: application/json'\--data'{  "insights": ["INSIGHT_COUNT", "INSIGHT_PLACES"],  "filter": {    "locationFilter": {      "circle": {        "latLng": { "latitude": 51.508, "longitude": -0.128},        "radius": 200      }    },    "typeFilter": { "includedPrimaryTypes": "restaurant" }  }}'

Python (gRPC)

fromgoogle.mapsimportareainsights_v1fromgoogle.maps.areainsights_v1.typesimport(ComputeInsightsRequest,Filter,LocationFilter,TypeFilter,Insight)fromgoogle.typeimportlatlng_pb2fromgoogle.oauth2importservice_accountdefget_area_insights():# Initialize the client with service accountcredentials=service_account.Credentials.from_service_account_file('path/to/service_account.json',scopes=['https://www.googleapis.com/auth/cloud-platform'])client=areainsights_v1.AreaInsightsClient(credentials=credentials)# Create location filter with circlelat_lng=latlng_pb2.LatLng(latitude=51.508,longitude=-0.128)location_filter=LocationFilter(circle=LocationFilter.Circle(lat_lng=lat_lng,radius=200))# Create type filter with primary typestype_filter=TypeFilter(included_primary_types=["restaurant"])# Create the main filterfilter=Filter(location_filter=location_filter,type_filter=type_filter)# Create the requestrequest=ComputeInsightsRequest(insights=[Insight.INSIGHT_COUNT,Insight.INSIGHT_PLACES],filter=filter)try:# Make the requestresponse=client.compute_insights(request=request)# Print resultsprint(f"Total count:{response.count}")print("\nPlaces found:")forplaceinresponse.place_insights:print(f"Place ID:{place.place}")exceptExceptionase:print(f"Error occurred:{e}")if__name__=="__main__":get_area_insights()

Custom polygon

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

As before, the place type used isrestaurant. This example also introducesthree other filters:

  • operatingStatus: This example counts only operational places.
  • priceLevel: This example counts only inexpensive and moderately pricedplaces.
  • ratingFilter: This example counts only places with a review score between4.0 and 5.0.

Rest

curl--location'https://areainsights.googleapis.com/v1:computeInsights'\--header'X-Goog-Api-Key:API_KEY'\--header'Content-Type: application/json'\--data'{    "insights": [ "INSIGHT_COUNT" ],    "filter": {        "locationFilter": {            "customArea": {                "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 }                    ]                }            }        },        "typeFilter": {            "includedTypes": "restaurant"        },        "operatingStatus": [ "OPERATING_STATUS_OPERATIONAL" ],        "priceLevels": [ "PRICE_LEVEL_INEXPENSIVE", "PRICE_LEVEL_MODERATE" ],        "ratingFilter": { "minRating": 4.0, "maxRating": 5.0 }    }}'

Python (gRPC)

fromgoogle.mapsimportareainsights_v1fromgoogle.maps.areainsights_v1.typesimport(ComputeInsightsRequest,Filter,LocationFilter,TypeFilter,Insight,RatingFilter,OperatingStatus,PriceLevel)fromgoogle.typeimportlatlng_pb2fromgoogle.oauth2importservice_accountdefget_area_insights():# Initialize the client with service accountcredentials=service_account.Credentials.from_service_account_file('path/to/service_account.json',scopes=['https://www.googleapis.com/auth/cloud-platform'])client=areainsights_v1.AreaInsightsClient(credentials=credentials)# Create coordinates for the polygoncoordinates=[latlng_pb2.LatLng(latitude=37.776,longitude=-122.666),latlng_pb2.LatLng(latitude=37.130,longitude=-121.898),latlng_pb2.LatLng(latitude=37.326,longitude=-121.598),latlng_pb2.LatLng(latitude=37.912,longitude=-122.247),latlng_pb2.LatLng(latitude=37.776,longitude=-122.666)# Closing point]# Create custom area with polygon using the nested structurelocation_filter=LocationFilter(custom_area=LocationFilter.CustomArea(polygon=LocationFilter.CustomArea.Polygon(coordinates=coordinates)))# Create type filtertype_filter=TypeFilter(included_types=["restaurant"])# Create rating filterrating_filter=RatingFilter(min_rating=4.0,max_rating=5.0)# Create the main filterfilter=Filter(location_filter=location_filter,type_filter=type_filter,operating_status=[OperatingStatus.OPERATING_STATUS_OPERATIONAL],price_levels=[PriceLevel.PRICE_LEVEL_INEXPENSIVE,PriceLevel.PRICE_LEVEL_MODERATE],rating_filter=rating_filter)# Create the requestrequest=ComputeInsightsRequest(insights=[Insight.INSIGHT_COUNT],filter=filter)try:# Make the requestresponse=client.compute_insights(request=request)# Print resultsprint(f"Total count:{response.count}")exceptExceptionase:print(f"Error occurred:{e}")if__name__=="__main__":get_area_insights()

Geographical area

This example uses aGeographical Area place ID to set the search area.These place IDs include the geometry of a place, such as a town or city. Theplace ID used here isChIJiQHsW0m3j4ARm69rRkrUF3w, which corresponds to thecity ofMountain View, California.

Passing the place ID to the Places Aggregate API sets the search area to the boundsof the geographic area. The place ID is passed usingplace, in the formatplaces/place_ID.

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

Rest

curl--location'https://areainsights.googleapis.com/v1:computeInsights'\--header'X-Goog-Api-Key:API_KEY'\--header'Content-Type: application/json'\--data'{    "insights": [        "INSIGHT_COUNT"    ],    "filter": {        "locationFilter": {            "region": {                "place": "places/ChIJiQHsW0m3j4ARm69rRkrUF3w"            }        },        "typeFilter": {            "includedTypes": [                "restaurant"            ]        }    }}'

Python (gRPC)

fromgoogle.mapsimportareainsights_v1fromgoogle.maps.areainsights_v1.typesimport(ComputeInsightsRequest,Filter,LocationFilter,TypeFilter,Insight)fromgoogle.oauth2importservice_accountdefget_area_insights():# Initialize the client with service accountcredentials=service_account.Credentials.from_service_account_file('path/to/service_account.json',scopes=['https://www.googleapis.com/auth/cloud-platform'])client=areainsights_v1.AreaInsightsClient(credentials=credentials)# Create location filter with regionlocation_filter=LocationFilter(region=LocationFilter.Region(place="places/ChIJiQHsW0m3j4ARm69rRkrUF3w"))# Create type filtertype_filter=TypeFilter(included_types=["restaurant"])# Create the main filterfilter=Filter(location_filter=location_filter,type_filter=type_filter)# Create the requestrequest=ComputeInsightsRequest(insights=[Insight.INSIGHT_COUNT],filter=filter)try:# Make the requestresponse=client.compute_insights(request=request)# Print resultsprint(f"Total count:{response.count}")exceptExceptionase:print(f"Error occurred:{e}")if__name__=="__main__":get_area_insights()

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-21 UTC.