-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpygeolocate.py
81 lines (65 loc) · 2.29 KB
/
xpygeolocate.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
import requests
from tkinter import *
base_url='https://maps.googleapis.com/maps/api/geocode/json?'
def write(statmsg):
stext.config(state=NORMAL)
stext.insert("end", statmsg + "\n")
stext.see("end")
stext.config(state=DISABLED)
def geo2add(geo):
try:
my_coord = {'latlng': geo, 'sensor':'true'}
response = requests.get(base_url, params = my_coord)
results = response.json()['results']
x_add = results[0]['formatted_address']
except (IndexError):
write("\nerror. unable to locate geotag: " + str(geo) + "\ncheck your arguments and try again")
else:
write("\nApproximate address: " + str(x_add))
def add2geo(add):
try:
get_tag = {'address': add, 'language':'en'}
response = requests.get(base_url, params = get_tag)
results = response.json()['results']
addy= results[0]['geometry']['location']
except (IndexError):
write("\nerror. unable to locate address: " + str(add) + "\ncheck your arguments and try again")
else:
write("\nApproximate geotag: " + str(addy['lat']) + str(addy['lng']))
def findit():
upick = ebox.get()
selection = pick.get()
write("Querying Google Maps for address: \n" + upick)
if selection == 1:
add2geo(str(upick))
else:
geo2add(str(upick))
'''GUI Elements'''
main = Tk()
main.title=("xPygeolocate")
titlelbl = Label(main, text="xPyGeolocate")
titlelbl.pack(fill=X, padx=20, pady=10)
'''radiobutton options'''
pick = IntVar()
pick.set(1)
chooselbl = Label(main, text="Choose an option:", justify=LEFT, padx=20)
chooselbl.pack(anchor=W)
atogbtn = Radiobutton(main, text="Address to Geotag", padx=20, pady=5, variable=pick, value=1)
atogbtn.pack(anchor=W)
gtoabtn = Radiobutton(main, text="Geotag to Address", padx=20, pady=5, variable=pick, value=2)
gtoabtn.pack(anchor=W)
'''text-box'''
elable = Label(main, text="Enter Geotag or Address to look-up")
elable.pack()
ebox = Entry(main, bd=3, width=30)
ebox.pack(fill=X, padx=20, pady=10)
'''buttons'''
gbtn = Button(main, text="Search", command=findit)
gbtn.pack(padx=3, pady=2)
qbtn = Button(main, justify=RIGHT, text="Quit", command=quit)
qbtn.pack(side=BOTTOM,padx=3, pady=2)
'''output box'''
stext = Text(main, width=55, height=15)
stext.pack(side=BOTTOM, padx=5, pady=5)
main.mainloop()