File size: 1,524 Bytes
d5ff050 dc8e36b d5ff050 dc8e36b d5ff050 dc8e36b d5ff050 dc8e36b d5ff050 dc8e36b b2f9c9a dc8e36b 2f1d1ae dc8e36b b2f9c9a dc8e36b b2f9c9a dc8e36b b2f9c9a dc8e36b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import streamlit as st
from serpapi import GoogleSearch
def fetch_google_maps_results(query=None, location=None, search_type="search"):
if not query and not location:
raise ValueError("Either 'query' or 'location' must be provided.")
params = {
"api_key": "YOUR_API_KEY",
"engine": "google_maps",
"type": search_type,
"google_domain": "google.it",
"hl": "it",
"gl": "it"
}
if query:
params["q"] = query
if location:
params["ll"] = location
search = GoogleSearch(params)
results = search.get_dict()
return results
st.title("Google Maps API Search via SerpAPI")
st.write("Enter a search query or a geographic location to fetch results from Google Maps.")
# Input fields
search_type = st.selectbox("Select Search Type:", ["search", "place"])
query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
location = st.text_input("Geographic Location (ll): (Format: '@latitude,longitude,zoom')")
# Button to trigger the API call
if st.button("Search"):
if not query and not location:
st.error("Please enter either a search query or a geographic location.")
else:
try:
results = fetch_google_maps_results(query=query, location=location, search_type=search_type)
# Display the results (you might want to format or filter this)
st.write(results)
except Exception as e:
st.error(f"Couldn't fetch the results. Error: {e}")
|