You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Web应用仪表盘无法获取移动端Firebase数据库提交的位置数据

移动端提交Firebase的位置数据无法在Web仪表盘展示,手动添加的数据却正常

我开发了一款移动端应用,可将用户位置信息(latitude、longitude、timestamp)提交至Firebase数据库;同时开发了Web仪表盘,用于在浏览器中展示该位置数据。但当前存在问题:移动端提交的数据无法在仪表盘显示,而手动向Firebase数据库添加结构一致的数据时,仪表盘却能正常展示。

以下是我的仪表盘代码:

// Function to fetch and display data
function fetchData() {
    console.log("Fetching data...");
    db.collection("locations").get().then((querySnapshot) => {
        if (querySnapshot.empty) {
            console.log("No documents found in 'locations' collection.");
            document.getElementById('data').innerHTML = '<p>No data found</p>';
            return;
        }
        console.log("Documents found in 'locations' collection: ", querySnapshot.size);
        querySnapshot.forEach((doc) => {
            const userId = doc.id;
            console.log(`Fetching subcollection 'dailyLocations' for userId: ${userId}`);
            doc.ref.collection("dailyLocations").get().then((subQuerySnapshot) => {
                if (subQuerySnapshot.empty) {
                    console.log(`No documents found in 'dailyLocations' subcollection for userId: ${userId}`);
                    document.getElementById('data').innerHTML += `<p>No location data for user: ${userId}</p>`;
                } else {
                    console.log(`Documents found in 'dailyLocations' for userId: ${userId}: `, subQuerySnapshot.size);
                    subQuerySnapshot.forEach((subDoc) => {
                        const data = subDoc.data();
                        const date = new Date(data.timestamp);
                        const dateString = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
                        document.getElementById('data').innerHTML += `<p>User: ${userId}, Latitude: ${data.latitude}, Longitude: ${data.longitude}, Timestamp: ${dateString}</p>`;
                    });
                }
            }).catch((error) => {
                console.error("Error fetching subcollection: ", error);
                document.getElementById('data').innerHTML += `<p>Error fetching location data for user: ${userId}</p>`;
            });
        });
    }).catch((error) => {
        console.error("Error fetching main collection: ", error);
        document.getElementById('data').innerHTML = '<p>Error fetching data</p>';
    });
}

fetchData();

我已尝试将数据库安全规则修改为允许任意读写,但问题仍未解决。

内容的提问来源于stack exchange,提问作者bipladverts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 05:52:34