forked from dev10110/hackMIT2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPhotoLatLong.py
37 lines (27 loc) · 1.12 KB
/
getPhotoLatLong.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
import exifread
def degToDec(coord):
latdec = float(coord[0][0].num)/coord[0][0].den+float(coord[0][1].num)/coord[0][1].den/60 + float(coord[0][2].num)/coord[0][2].den/3600
if coord[2] == 'S':
latdec = latdec*-1
lngdec = float(coord[1][0].num)/coord[1][0].den+float(coord[1][1].num)/coord[1][1].den/60 + float(coord[1][2].num)/coord[1][2].den/3600
if coord[3] == 'W':
lngdec = lngdec*-1
return [latdec,lngdec]
def getLatLong(fileLoc):
#pass in file location as fileLoc (string). don't forget .jpg!
#returns lat and long as list = [lat,long]
f = open(fileLoc,'rb')
metadata = exifread.process_file(f,details=False)
for key in metadata.keys():
if key == 'GPS GPSLatitude':
lat = metadata[key]
elif key == 'GPS GPSLongitude':
lng = metadata[key]
elif key == 'GPS GPSLatitudeRef':
latdir = str(metadata[key])
elif key == 'GPS GPSLongitudeRef':
lngdir = str(metadata[key])
lat = lat.values
lng = lng.values
return degToDec([lat,lng,latdir,lngdir])
print(getLatLong('100075_lowres.jpg'))