-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeo.py
More file actions
60 lines (50 loc) · 2.19 KB
/
geo.py
File metadata and controls
60 lines (50 loc) · 2.19 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Uses the google maps API to find the nearest park to a lat-lon point
from googleplaces import GooglePlaces, types, lang
from geopy.geocoders import Nominatim
import tkinter as tk
from PIL import Image, ImageTk
import io
YOUR_API_KEY = 'AIzaSyDQBb_fJ3Ppby0et4BAHtj-0Lvtpd97Dc0'
geolocator = Nominatim()
latlong="42,-71"
def reverse_search(latlong):
"""Reverse searches the Google Maps API,give it a latitude and longitude and returns an address"""
location = geolocator.reverse(latlong)
def find_attraction(latlong):
"""Searches google for nearby attractions as specified by user, ie. parks"""
google_places = GooglePlaces(YOUR_API_KEY)
query_result = google_places.nearby_search(
location = latlong, keyword='Park',
radius = 10000, types=[types.TYPE_PARK])
return query_result
def attraction_info(query_result):
"""For each google result, the program prints the address of the attraction, website, and rating. Then prints one photo per attraction mentioned. More photos can be printed by editing the statement if num<2."""
window = tk.Toplevel()
geo_root = tk.Toplevel()
for place in query_result.places:
num = 1
for photo in place.photos:
if num<2:
if place.website:
info="{}\n{}\n{}".format(str(place.vicinity),str(place.website),str(place.rating))
else:
info="{}\n{}".format(str(place.vicinity),str(place.rating))
photo.get(maxheight=500, maxwidth=500)
window.title(str(place.name))
w = tk.Label(geo_root, text=info)
window.geometry("300x300")
window.configure(background='grey')
img = ImageTk.PhotoImage(Image.open(io.BytesIO(photo.data)))
print(type(img))
panel = tk.Label(window, image = img)
panel.pack(side = "right", fill = "x", expand = "yes")
num=num+1
w.pack()
geo_root.mainloop()
return img
if __name__ == "__main__":
window = tk.Tk()
geo_root = tk.Tk()
address=reverse_search(latlong)
att=find_attraction(latlong)
attraction_info(att, geo_root, window)