File size: 2,070 Bytes
dcb338b
 
 
 
 
 
 
05d87a8
 
dcb338b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce4db09
dcb338b
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# app.py
import streamlit as st
import geopy.distance
import math
import time

# 初始寶藏設定(可以之後做成可以動態新增)
treasure_lat = 24.985782273285125  # Example: 台北101
treasure_lon = 121.28879338465508
treasure_name = "Hidden Treasure"
treasure_glb_url = "https://yourspace.hf.space/path/to/treasure.glb"

# UI畫面
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("太遠了,請靠近寶藏點!")

# 加入Google Map 顯示位置(可選)
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)