-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps_utils.py
47 lines (38 loc) · 1.66 KB
/
gps_utils.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
from PyQt5.QtWebEngineWidgets import QWebEngineView
import io
import folium
# it allows to do the conversion to degrees.
def convert_to_degrees(value):
d = float(value[0])
m = float(value[1]) / 60.0
s = float(value[2]) / 3600.0
return d + m + s
# it allows calculating latitude, longitude and create the relative map in those coordinates.
def gps_map(gps_exif):
latitude, longitude = None, None
gps_latitude = gps_exif['GPSLatitude']
gps_latitude_ref = gps_exif['GPSLatitudeRef']
gps_longitude = gps_exif['GPSLongitude']
gps_longitude_ref = gps_exif['GPSLongitudeRef']
if gps_latitude and gps_latitude_ref and gps_longitude and gps_longitude_ref:
latitude = convert_to_degrees(gps_latitude)
if gps_latitude_ref != 'N':
latitude = 0 - latitude
longitude = convert_to_degrees(gps_longitude)
if gps_longitude_ref != 'E':
longitude = 0 - longitude
# Google Maps link.
url = '<a href="https://www.google.com/maps/search/?api=1&query={0},{1}"> Google Maps </a>'.format(
latitude, longitude)
# print('url: {}'.format(url))
# create the map from coordinates.
coordinate = (latitude, longitude)
m = folium.Map(title='GPS Location', zoom_start=18, location=coordinate)
popup = folium.Popup(f'<h4>For more information go to {url}</h4>', max_width=len('For more information') * 9)
folium.Marker(coordinate, popup=popup).add_to(m)
# save map data to data object.
data = io.BytesIO()
m.save(data, close_file=False)
web_view = QWebEngineView()
web_view.setHtml(data.getvalue().decode())
return web_view