Using Google Places API for Subway Station Searches and Information Retrieval
What is Google Places API?
Google Places API is part of the Google Maps Platform, providing extensive location data and detailed place information. So, what can it do?
1.Add new locations to the Google database.
2.Retrieve reviews and ratings of a place.
3.Extract detailed information such as address, contact number, business hours, etc.
4.Search for relevant places within a specified area.
How to Use Google Places API for Subway Station Searches and Information Retrieval?
First, obtain an API key by visiting the Google Cloud Console, creating a project, enabling the Places API, and generating an API key. Then, install the necessary Python libraries and set up environment variables.
Python
pip install googlemaps langchain-community
import os
os.environ["GPLACES_API_KEY"] = "Your API key"
Next, use the Google Places API to perform location searches.
Python
from langchain_community.tools import GooglePlacesTool
import os
if 'GOOGLE_API_KEY' not in os.environ:
print("⚠️ Warning: Environment variable 'GOOGLE_API_KEY' not found.")
print(" Please set up your Google Cloud API key first.")
try:
places = GooglePlacesTool()
except Exception as e:
print(f"❌ Failed to initialize GooglePlacesTool: {e}")
exit()
search_query = "museums in New York City"
print(f"? Searching using GooglePlacesTool: '{search_query}'...")
result = places.run(search_query)
print("\n--- Search results ---")
print(result)
Finally, return the relevant search results and save them.