इस सेक्शन में, Places Insights 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()
प्राइमरी टाइप का इस्तेमाल करना
इस उदाहरण में, पहले उदाहरण के अनुरोध में बदलाव किया गया है, ताकि सिर्फ़ उन जगहों को शामिल किया जा सके जिनकी संख्या में restaurant
का primaryType
है.
आराम का समय
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 Insights API को जगह का आईडी देने पर, खोज के लिए जगह की सीमा, भौगोलिक इलाके की सीमा पर सेट हो जाती है. जगह का आईडी, place
का इस्तेमाल करके, places/place_ID
फ़ॉर्मैट में पास किया जाता है.
भौगोलिक क्षेत्र का प्लेस आईडी पाने के लिए, इनमें से कोई भी तरीका अपनाएं:
- जगह का आईडी ढूंढने वाला टूल
- Geocoding API
- टेक्स्ट खोज (नया)
- आस-पास की जगहों की जानकारी (नया)
- Address Validation 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" ] } } }'
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()