উদাহরণ

এই বিভাগে প্লেসেস অ্যাগ্রিগেট এপিআই-এর জন্য কয়েকটি উদাহরণমূলক অনুরোধ আলোচনা করা হয়েছে।

ক্লায়েন্ট লাইব্রেরি ইনস্টলেশন

পাইথন (gRPC) উদাহরণগুলো ব্যবহার করার জন্য, আপনাকে অবশ্যই প্লেসেস অ্যাগ্রিগেট এপিআই (Places Aggregate API)-এর নির্দিষ্ট ক্লায়েন্ট লাইব্রেরি এবং গুগল অথ (Google Auth) লাইব্রেরি ইনস্টল করতে হবে:

pip install google-maps-areainsights google-auth

বৃত্তের মধ্যে স্থান ফেরত দিন।

লন্ডনের ট্রাফালগার স্কোয়ারের ২০০ মিটার ব্যাসার্ধের মধ্যে অবস্থিত সমস্ত রেস্তোরাঁর তালিকা দিন।

  • অনুসন্ধান এলাকাটি একটি নির্দিষ্ট অক্ষাংশ ও দ্রাঘিমাংশকে কেন্দ্র করে অবস্থিত একটি বৃত্ত। এই বৃত্তের ব্যাসার্ধ ২০০ মিটার, যা অনুসন্ধান এলাকার আকার নির্ধারণ করে।
  • অনুরোধকৃত স্থানের ধরণটি হলো রেস্তোরাঁ, এবং এটি 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" }
  }
}'
    

পাইথন (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()
  

স্থানের প্রকারগুলি বাদ দিন

আপনি গণনা থেকে স্থানের প্রকারভেদ বাদ দিতে পারেন।

নিম্নলিখিত অনুরোধটি প্রথম উদাহরণের মতোই, তবে এটি typeFiltersexcludedTypes যোগ করে। আপনি 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"
            ]
        }
    }
}'
    

পাইথন (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" }
  }
}'
    

পাইথন (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 নির্দিষ্ট করলে অনুসন্ধানটি এমন ছোট এলাকায় সীমাবদ্ধ থাকে যা থেকে সর্বোচ্চ ১০০টি স্থানের আইডি পাওয়া যায়। এর চেয়ে বড় এলাকার জন্য, এই সীমাবদ্ধতা এড়াতে INSIGHTS_COUNT ব্যবহার করুন, যাতে পরিষেবাটিকে আলাদা আলাদা স্থানের আইডি ফেরত দিতে না হয়।

আগের মতোই, ব্যবহৃত স্থানের ধরণটি হলো restaurant । এই উদাহরণটিতে আরও তিনটি ফিল্টার যুক্ত করা হয়েছে:

  • operatingStatus : এই উদাহরণে শুধুমাত্র চালু স্থানগুলো গণনা করা হয়।
  • priceLevel : এই উদাহরণে শুধুমাত্র স্বল্পমূল্যের এবং মাঝারি মূল্যের স্থানগুলো গণনা করা হয়েছে।
  • ratingFilter : এই উদাহরণটি শুধুমাত্র সেইসব স্থান গণনা করে যাদের রিভিউ স্কোর ৪.০ থেকে ৫.০-এর মধ্যে।

বিশ্রাম

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 }
    }
}'
    

পাইথন (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"
            ]
        }
    }
}'
    

পাইথন (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()