এই বিভাগটি Places Aggregate API-তে উদাহরণ অনুরোধের একটি সিরিজ কভার করে।
একটি বৃত্তের মধ্যে স্থানগুলি ফেরত দিন
লন্ডনের ট্রাফালগার স্কয়ারের ২০০ মিটার ব্যাসার্ধের মধ্যে সমস্ত রেস্তোরাঁ ফিরিয়ে দিন।
- অনুসন্ধান এলাকাটি একটি নির্দিষ্ট অক্ষাংশ এবং দ্রাঘিমাংশকে কেন্দ্র করে একটি বৃত্ত। এই বৃত্তের ব্যাসার্ধ ২০০ মিটার, যা অনুসন্ধান এলাকার আকার নির্ধারণ করে।
- অনুরোধ করা স্থানের ধরণটি হল restaurant, এবং এটি
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" } } }'
পাইথন (জিআরপিসি)
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" ] } } }'
পাইথন (জিআরপিসি)
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" } } }'
পাইথন (জিআরপিসি)
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 টি স্থানের ID ফেরত দেওয়ার জন্য যথেষ্ট ছোট এলাকায় সীমাবদ্ধ থাকে। বৃহত্তর এলাকার জন্য, এই সীমাবদ্ধতাটি এড়িয়ে যেতে INSIGHTS_COUNT ব্যবহার করুন যাতে পরিষেবাটিকে পৃথক স্থানের ID ফেরত দেওয়ার প্রয়োজন না হয়।
আগের মতোই, ব্যবহৃত স্থানের ধরণ হল 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 } } }'
পাইথন (জিআরপিসি)
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 , যা ক্যালিফোর্নিয়ার মাউন্টেন ভিউ শহরের সাথে সম্পর্কিত।
প্লেস আইডি প্লেস এগ্রিগেট এপিআই-তে পাস করলে সার্চ এরিয়া ভৌগোলিক এলাকার সীমানায় সেট হয়ে যায়। প্লেস আইডি place ব্যবহার করে places/ place_ID ফর্ম্যাটে পাস করা হয়।
আপনি নিম্নলিখিত যেকোনো উপায়ে একটি ভৌগোলিক এলাকা স্থান আইডি পেতে পারেন:
- স্থান আইডি ফাইন্ডার
- জিওকোডিং এপিআই
- টেক্সট সার্চ (নতুন)
- কাছাকাছি অনুসন্ধান (নতুন)
- ঠিকানা যাচাইকরণ API
- স্থান স্বয়ংসম্পূর্ণ
বিশ্রাম
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" ] } } }'
পাইথন (জিআরপিসি)
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()