KJ commited on
Commit ·
cfbb7e9
1
Parent(s): 7f43dee
fixing errors
Browse files- app.py +11 -28
- requirements.txt +4 -1
app.py
CHANGED
|
@@ -4,6 +4,8 @@ from sqlalchemy import create_engine, text
|
|
| 4 |
from sshtunnel import SSHTunnelForwarder
|
| 5 |
import os
|
| 6 |
import tempfile
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# --- Config ---
|
| 9 |
st.set_page_config(page_title="GPS Map Viewer", layout="wide")
|
|
@@ -19,7 +21,6 @@ MYSQL_USER = st.secrets["MYSQL_USER"]
|
|
| 19 |
MYSQL_PASSWORD = st.secrets["MYSQL_PASSWORD"]
|
| 20 |
MYSQL_DB = st.secrets["DB_NAME"]
|
| 21 |
MYSQL_PORT = int(st.secrets["MYSQL_PORT"])
|
| 22 |
-
GOOGLE_MAPS_API_KEY = st.secrets["GOOGLE_MAPS_API_KEY"]
|
| 23 |
|
| 24 |
# --- SSH Key File ---
|
| 25 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pem") as temp_file:
|
|
@@ -55,33 +56,15 @@ def load_gps_data():
|
|
| 55 |
|
| 56 |
gps_data = load_gps_data()
|
| 57 |
|
| 58 |
-
# --- Display Map ---
|
| 59 |
if not gps_data.empty:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
const map = new google.maps.Map(document.getElementById("map"), {{
|
| 69 |
-
zoom: 14,
|
| 70 |
-
center: {{ lat: points[0].latitude, lng: points[0].longitude }},
|
| 71 |
-
mapTypeId: 'roadmap'
|
| 72 |
-
}});
|
| 73 |
-
const path = points.map(p => new google.maps.LatLng(p.latitude, p.longitude));
|
| 74 |
-
new google.maps.Polyline({{
|
| 75 |
-
path,
|
| 76 |
-
geodesic: true,
|
| 77 |
-
strokeColor: "#FF0000",
|
| 78 |
-
strokeOpacity: 1.0,
|
| 79 |
-
strokeWeight: 2,
|
| 80 |
-
map: map
|
| 81 |
-
}});
|
| 82 |
-
}}
|
| 83 |
-
window.onload = initMap;
|
| 84 |
-
</script>
|
| 85 |
-
""", height=700)
|
| 86 |
else:
|
| 87 |
st.info("No GPS data available.")
|
|
|
|
| 4 |
from sshtunnel import SSHTunnelForwarder
|
| 5 |
import os
|
| 6 |
import tempfile
|
| 7 |
+
import folium
|
| 8 |
+
from streamlit_folium import st_folium
|
| 9 |
|
| 10 |
# --- Config ---
|
| 11 |
st.set_page_config(page_title="GPS Map Viewer", layout="wide")
|
|
|
|
| 21 |
MYSQL_PASSWORD = st.secrets["MYSQL_PASSWORD"]
|
| 22 |
MYSQL_DB = st.secrets["DB_NAME"]
|
| 23 |
MYSQL_PORT = int(st.secrets["MYSQL_PORT"])
|
|
|
|
| 24 |
|
| 25 |
# --- SSH Key File ---
|
| 26 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pem") as temp_file:
|
|
|
|
| 56 |
|
| 57 |
gps_data = load_gps_data()
|
| 58 |
|
| 59 |
+
# --- Display Map using folium ---
|
| 60 |
if not gps_data.empty:
|
| 61 |
+
start_lat = gps_data.iloc[0]["latitude"]
|
| 62 |
+
start_lon = gps_data.iloc[0]["longitude"]
|
| 63 |
+
|
| 64 |
+
m = folium.Map(location=[start_lat, start_lon], zoom_start=14)
|
| 65 |
+
points = gps_data[["latitude", "longitude"]].values.tolist()
|
| 66 |
+
folium.PolyLine(points, color="red", weight=3).add_to(m)
|
| 67 |
+
|
| 68 |
+
st_folium(m, width=700, height=600)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
else:
|
| 70 |
st.info("No GPS data available.")
|
requirements.txt
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
|
|
| 1 |
sshtunnel
|
| 2 |
sqlalchemy
|
| 3 |
pymysql
|
| 4 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
sshtunnel
|
| 3 |
sqlalchemy
|
| 4 |
pymysql
|
| 5 |
+
pandas
|
| 6 |
+
folium
|
| 7 |
+
streamlit-folium
|