Suwon_multiculturalism / services /google_maps_service.py
helloguddn (PC helloguddn)
feat: 의존성, chat 엔드포인트, gemini function calling, 이미지 추출, Maps 연동, 노동법 RAG(google.text-embedding-004)
f4bf832
Raw History Blame Contribute Delete
1.09 kB
import os
import googlemaps
_client: googlemaps.Client | None = None
def get_client() -> googlemaps.Client:
global _client
if _client is None:
api_key = os.getenv("GOOGLE_MAPS_API_KEY")
if not api_key:
raise RuntimeError("GOOGLE_MAPS_API_KEY environment variable is not set")
_client = googlemaps.Client(key=api_key)
return _client
def search_nearby(
lat: float,
lng: float,
keyword: str,
radius: int = 5000,
) -> list[dict]:
client = get_client()
result = client.places_nearby(
location=(lat, lng),
radius=radius,
keyword=keyword,
language="ko",
)
places = []
for place in result.get("results", [])[:5]:
loc = place["geometry"]["location"]
places.append(
{
"name": place.get("name", ""),
"lat": loc["lat"],
"lng": loc["lng"],
"address": place.get("vicinity", ""),
"phone": place.get("formatted_phone_number", ""),
}
)
return places