Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,25 +20,28 @@ farm_data = load_farm_data()
|
|
20 |
st.write(
|
21 |
"""
|
22 |
<script>
|
23 |
-
|
24 |
-
(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
</script>
|
33 |
-
<input type="hidden" id="user_lat" name="latitude">
|
34 |
-
<input type="hidden" id="user_lon" name="longitude">
|
35 |
-
<form action="#" method="get">
|
36 |
-
<input type="submit" id="submit_button" style="display:none">
|
37 |
-
</form>
|
38 |
""",
|
39 |
unsafe_allow_html=True,
|
40 |
)
|
41 |
|
|
|
42 |
# Extract user location from query params
|
43 |
query_params = st.query_params
|
44 |
user_lat = query_params.get("latitude", [None])[0]
|
|
|
20 |
st.write(
|
21 |
"""
|
22 |
<script>
|
23 |
+
function getLocation() {
|
24 |
+
navigator.geolocation.getCurrentPosition(
|
25 |
+
(position) => {
|
26 |
+
const latitude = position.coords.latitude;
|
27 |
+
const longitude = position.coords.longitude;
|
28 |
+
const url = new URL(window.location.href);
|
29 |
+
url.searchParams.set('latitude', latitude);
|
30 |
+
url.searchParams.set('longitude', longitude);
|
31 |
+
window.location.href = url.toString();
|
32 |
+
},
|
33 |
+
(error) => {
|
34 |
+
alert('Error getting location. Please ensure location services are enabled.');
|
35 |
+
}
|
36 |
+
);
|
37 |
+
}
|
38 |
+
getLocation();
|
39 |
</script>
|
|
|
|
|
|
|
|
|
|
|
40 |
""",
|
41 |
unsafe_allow_html=True,
|
42 |
)
|
43 |
|
44 |
+
|
45 |
# Extract user location from query params
|
46 |
query_params = st.query_params
|
47 |
user_lat = query_params.get("latitude", [None])[0]
|