-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagrovets_location.py
45 lines (35 loc) · 1.48 KB
/
agrovets_location.py
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 requests
def find_nearest_agrovets(api_key, location, radius=50000, keyword="agrovet"):
url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
params = {
"location": location, # Latitude and Longitude of Nairobi center
"radius": radius,
"keyword": keyword,
"key": api_key
}
response = requests.get(url, params=params)
if response.status_code == 200:
results = response.json().get("results", [])
print(f"result:{results}")
return results
else:
print(f"Error: Received status code {response.status_code}. Response: {response.text}")
return None
def get_place_details(api_key, place_id):
url = "https://maps.googleapis.com/maps/api/place/details/json"
params = {
"place_id": place_id,
"fields": "name,vicinity,formatted_phone_number",
"key": api_key
}
response = requests.get(url, params=params)
if response.status_code == 200:
result = response.json().get("result", {})
return result
else:
print(f"Error: Received status code {response.status_code}. Response: {response.text}")
return None
def generate_google_maps_link(place_id):
return f"https://www.google.com/maps/place/?q=place_id:{place_id}"
def generate_photo_url(photo_reference, api_key):
return f"https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference={photo_reference}&key={api_key}"