|
|
|
|
|
import streamlit as st |
|
|
import geopy.distance |
|
|
import math |
|
|
import time |
|
|
|
|
|
|
|
|
treasure_lat = 24.985782273285125 |
|
|
treasure_lon = 121.28879338465508 |
|
|
treasure_name = "Hidden Treasure" |
|
|
treasure_glb_url = "https://yourspace.hf.space/path/to/treasure.glb" |
|
|
|
|
|
|
|
|
st.set_page_config(page_title="AR GPS Treasure Hunt", layout="wide") |
|
|
|
|
|
st.title("🏴☠️ AR GPS Treasure Hunt Game") |
|
|
|
|
|
st.markdown(""" |
|
|
1. 開啟手機GPS定位權限 |
|
|
2. 走動到指定地點10公尺內,即可看到寶藏出現! |
|
|
""") |
|
|
|
|
|
|
|
|
user_lat = st.number_input("你的目前緯度 (Latitude)", format="%.6f") |
|
|
user_lon = st.number_input("你的目前經度 (Longitude)", format="%.6f") |
|
|
|
|
|
if st.button("檢查寶藏位置"): |
|
|
|
|
|
player_loc = (user_lat, user_lon) |
|
|
treasure_loc = (treasure_lat, treasure_lon) |
|
|
distance = geopy.distance.geodesic(player_loc, treasure_loc).meters |
|
|
|
|
|
st.write(f"距離寶藏: **{distance:.2f}公尺**") |
|
|
|
|
|
if distance <= 10: |
|
|
st.success(f"🎉 你找到 {treasure_name} 了!") |
|
|
|
|
|
st.markdown(f""" |
|
|
<model-viewer |
|
|
src="{treasure_glb_url}" |
|
|
ar |
|
|
ar-modes="scene-viewer webxr quick-look" |
|
|
environment-image="neutral" |
|
|
auto-rotate |
|
|
camera-controls |
|
|
style="width: 100%; height: 500px;"> |
|
|
</model-viewer> |
|
|
""", unsafe_allow_html=True) |
|
|
else: |
|
|
st.info("太遠了,請靠近寶藏點!") |
|
|
|
|
|
|
|
|
st.markdown("---") |
|
|
st.write("🌎 地圖視覺化 (之後可以自動定位)") |
|
|
|
|
|
google_map_embed = f""" |
|
|
<iframe width="100%" height="400" |
|
|
frameborder="0" style="border:0" |
|
|
referrerpolicy="no-referrer-when-downgrade" |
|
|
src="https://www.google.com/maps/embed/v1/place?key=AIzaSyCbaJdQHiF6SgKES_3NvwPV-Xu9h8ROYZs |
|
|
&q={treasure_lat},{treasure_lon}" allowfullscreen> |
|
|
</iframe> |
|
|
""" |
|
|
st.markdown(google_map_embed, unsafe_allow_html=True) |
|
|
|