File size: 1,095 Bytes
d5ff050
ff80b22
d5ff050
5be00a0
 
ff80b22
 
 
 
 
 
 
 
5be00a0
6b249d3
 
2f1d1ae
30b7d57
 
 
 
ff80b22
 
 
30b7d57
6b249d3
5be00a0
b2f9c9a
5be00a0
30b7d57
6b249d3
a6bc7dc
30b7d57
 
 
dc8e36b
6b249d3
5be00a0
ff80b22
dc8e36b
 
5be00a0
ff80b22
 
 
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
import streamlit as st
from serpapi import GoogleSearch

def fetch_google_maps_results(query=None, search_type="search"):
    if not query:
        raise ValueError("The 'query' must be provided.")

    params = {
        "api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
        "type": search_type,
        "google_domain": "google.it",
        "hl": "it",
        "gl": "it",
        "q": query
    }






    search = GoogleSearch(params)
    results = search.get_dict()
    return results

st.title("Google Maps API Search via SerpAPI")
st.write("Enter a search query to fetch results from Google Maps.")

# Input field

query = st.text_input("Search Query (q): (Use for regular Google Maps search)")




# Button to trigger the API call
if st.button("Search"):
    if not query:
        st.error("Please enter a search query.")
    else:
        try:
            results = fetch_google_maps_results(query=query)
            st.write(results)  # Display the results
        except Exception as e:
            st.error(f"Couldn't fetch the results. Error: {e}")