उदाहरण

इस सेक्शन में, Places Aggregate API को किए गए अनुरोधों के उदाहरण दिए गए हैं.

किसी सर्कल में मौजूद जगहों की जानकारी पाना

लंदन के ट्रैफ़लगर स्क्वेयर के 200 मीटर के दायरे में मौजूद सभी रेस्टोरेंट दिखाओ.

  • खोज का दायरा, किसी अक्षांश और देशांतर के हिसाब से तय किया गया एक सर्कल होता है. इस सर्कल की त्रिज्या 200 मीटर है. इससे खोज के दायरे का साइज़ तय होता है.
  • अनुरोध किया गया जगह का टाइप, रेस्टोरेंट है. इसे typeFilters में मौजूद includedTypes का इस्तेमाल करके पास किया जाता है.
  • INSIGHTS_COUNT का इस्तेमाल करके, संख्या का अनुरोध किया जाता है. साथ ही, INSIGHTS_PLACES का इस्तेमाल करके, प्लेस आईडी का अनुरोध किया जाता है.

आराम का समय

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)

from google.maps import areainsights_v1
from google.maps.areainsights_v1.types import (
    ComputeInsightsRequest,
    Filter,
    LocationFilter,
    TypeFilter,
    Insight
)
from google.type import latlng_pb2
from google.oauth2 import service_account

def get_area_insights():
    # Initialize the client
    credentials = 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 circle
    lat_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
    type_filter = TypeFilter(
        included_types=["restaurant"]
    )

    # Create the main filter
    filter = Filter(
        location_filter=location_filter,
        type_filter=type_filter
    )

    # Create the request
    request = ComputeInsightsRequest(
        insights=[
            Insight.INSIGHT_COUNT,
            Insight.INSIGHT_PLACES
        ],
        filter=filter
    )

    try:
        # Make the request
        response = client.compute_insights(request=request)
        
        # Print results
        print(f"Total count: {response.count}")
        print("\nPlaces found:")
        for place in response.place_insights:
            print(f"Place ID: {place.place}")

    except Exception as e:
        print(f"Error occurred: {e}")

if __name__ == "__main__":
    get_area_insights()
  

जगहों के टाइप को बाहर रखें

जगह के टाइप को गिनती से बाहर रखा जा सकता है.

यहां दिया गया अनुरोध, पहले उदाहरण जैसा ही है. हालांकि, इसमें typeFilters में excludedTypes जोड़ा गया है. includedTypes और excludedTypes के लिए, स्ट्रिंग या स्ट्रिंग के कलेक्शन का इस्तेमाल किया जा सकता है.

इस उदाहरण में, restaurant की गिनती से दो तरह की जगहों को हटाया गया है: cafe और bakery.

आराम का समय

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)

from google.maps import areainsights_v1
from google.maps.areainsights_v1.types import (
    ComputeInsightsRequest,
    Filter,
    LocationFilter,
    TypeFilter,
    Insight
)
from google.type import latlng_pb2
from google.oauth2 import service_account

def get_area_insights():
    # Initialize the client with service account
    credentials = 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 circle
    lat_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 types
    type_filter = TypeFilter(
        included_types=["restaurant"],
        excluded_types=["cafe", "bakery"]
    )

    # Create the main filter
    filter = Filter(
        location_filter=location_filter,
        type_filter=type_filter
    )

    # Create the request
    request = ComputeInsightsRequest(
        insights=[
            Insight.INSIGHT_COUNT,
            Insight.INSIGHT_PLACES
        ],
        filter=filter
    )

    try:
        # Make the request
        response = client.compute_insights(request=request)
        
        # Print results
        print(f"Total count: {response.count}")
        print("\nPlaces found:")
        for place in response.place_insights:
            print(f"Place ID: {place.place}")

    except Exception as e:
        print(f"Error occurred: {e}")

if __name__ == "__main__":
    get_area_insights()
  

प्राइमरी टाइप का इस्तेमाल करना

इस उदाहरण में, पहले उदाहरण के अनुरोध में बदलाव किया गया है, ताकि सिर्फ़ उन जगहों को शामिल किया जा सके जिनमें primaryType की संख्या restaurant है.

आराम का समय

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)

from google.maps import areainsights_v1
from google.maps.areainsights_v1.types import (
    ComputeInsightsRequest,
    Filter,
    LocationFilter,
    TypeFilter,
    Insight
)
from google.type import latlng_pb2
from google.oauth2 import service_account

def get_area_insights():
    # Initialize the client with service account
    credentials = 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 circle
    lat_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 types
    type_filter = TypeFilter(
        included_primary_types=["restaurant"]
    )

    # Create the main filter
    filter = Filter(
        location_filter=location_filter,
        type_filter=type_filter
    )

    # Create the request
    request = ComputeInsightsRequest(
        insights=[
            Insight.INSIGHT_COUNT,
            Insight.INSIGHT_PLACES
        ],
        filter=filter
    )

    try:
        # Make the request
        response = client.compute_insights(request=request)
        
        # Print results
        print(f"Total count: {response.count}")
        print("\nPlaces found:")
        for place in response.place_insights:
            print(f"Place ID: {place.place}")

    except Exception as e:
        print(f"Error occurred: {e}")

if __name__ == "__main__":
    get_area_insights()
  

कस्टम पॉलीगॉन

इस उदाहरण में, खोज के दायरे को तय करने के लिए कस्टम पॉलीगॉन का इस्तेमाल करने का तरीका बताया गया है. ध्यान रखें कि INSIGHTS_PLACES तय करने से, खोज को ऐसे छोटे इलाकों तक सीमित कर दिया जाता है जहां ज़्यादा से ज़्यादा 100 जगहों के आईडी मिल सकते हैं. बड़े इलाकों के लिए, इस सीमा को बायपास करने के लिए INSIGHTS_COUNT का इस्तेमाल करें, ताकि सेवा को अलग-अलग प्लेस आईडी न दिखाने पड़ें.

पहले की तरह, इस्तेमाल किया गया जगह का टाइप restaurant है. इस उदाहरण में, तीन अन्य फ़िल्टर भी दिखाए गए हैं:

  • operatingStatus: इस उदाहरण में, सिर्फ़ उन जगहों को गिना जाता है जहां कारोबार चल रहा है.
  • priceLevel: इस उदाहरण में, सिर्फ़ कम और सामान्य कीमत वाले रेस्टोरेंट की गिनती की गई है.
  • ratingFilter: इस उदाहरण में, सिर्फ़ उन जगहों को शामिल किया गया है जिनकी समीक्षा का स्कोर 4.0 से 5.0 के बीच है.

आराम का समय

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)

from google.maps import areainsights_v1
from google.maps.areainsights_v1.types import (
    ComputeInsightsRequest,
    Filter,
    LocationFilter,
    TypeFilter,
    Insight,
    RatingFilter,
    OperatingStatus,
    PriceLevel
)
from google.type import latlng_pb2
from google.oauth2 import service_account

def get_area_insights():
    # Initialize the client with service account
    credentials = 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 polygon
    coordinates = [
        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 structure
    location_filter = LocationFilter(
        custom_area=LocationFilter.CustomArea(
            polygon=LocationFilter.CustomArea.Polygon(coordinates=coordinates)
        )
    )

    # Create type filter
    type_filter = TypeFilter(
        included_types=["restaurant"]
    )

    # Create rating filter
    rating_filter = RatingFilter(
        min_rating=4.0,
        max_rating=5.0
    )

    # Create the main filter
    filter = 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 request
    request = ComputeInsightsRequest(
        insights=[Insight.INSIGHT_COUNT],
        filter=filter
    )

    try:
        # Make the request
        response = client.compute_insights(request=request)
        
        # Print results
        print(f"Total count: {response.count}")

    except Exception as e:
        print(f"Error occurred: {e}")

if __name__ == "__main__":
    get_area_insights()
    
  

भौगोलिक जगह

इस उदाहरण में, खोज के दायरे को सेट करने के लिए भौगोलिक क्षेत्र के प्लेस आईडी का इस्तेमाल किया गया है. इन जगहों के आईडी में, किसी जगह की ज्यामिति शामिल होती है. जैसे, कोई कस्बा या शहर. यहां इस्तेमाल किया गया जगह का आईडी ChIJiQHsW0m3j4ARm69rRkrUF3w है. यह माउंटेन व्यू, कैलिफ़ोर्निया शहर से मेल खाता है.

जगह का आईडी, Places Aggregate API को पास करने से, खोज के लिए जगह का दायरा, भौगोलिक इलाके की सीमाओं पर सेट हो जाता है. जगह का आईडी, place का इस्तेमाल करके पास किया जाता है. इसका फ़ॉर्मैट places/place_ID होता है.

किसी भौगोलिक क्षेत्र का प्लेस आईडी पाने के लिए, इनमें से कोई भी तरीका इस्तेमाल किया जा सकता है:

आराम का समय

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)

from google.maps import areainsights_v1
from google.maps.areainsights_v1.types import (
    ComputeInsightsRequest,
    Filter,
    LocationFilter,
    TypeFilter,
    Insight
)
from google.oauth2 import service_account

def get_area_insights():
    # Initialize the client with service account
    credentials = 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 region
    location_filter = LocationFilter(
        region=LocationFilter.Region(
            place="places/ChIJiQHsW0m3j4ARm69rRkrUF3w"
        )
    )

    # Create type filter
    type_filter = TypeFilter(
        included_types=["restaurant"]
    )

    # Create the main filter
    filter = Filter(
        location_filter=location_filter,
        type_filter=type_filter
    )

    # Create the request
    request = ComputeInsightsRequest(
        insights=[Insight.INSIGHT_COUNT],
        filter=filter
    )

    try:
        # Make the request
        response = client.compute_insights(request=request)
        
        # Print results
        print(f"Total count: {response.count}")

    except Exception as e:
        print(f"Error occurred: {e}")

if __name__ == "__main__":
    get_area_insights()