forked from 20266142/Overheard
second: open camera
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
import { collection, query, where, getDocs } from 'firebase/firestore'; // tools for building and running db queries
|
||||
import { db } from './config'; // database connection
|
||||
import { getQueryPrefix } from '$lib/utils/geohash'; // convert coordinates into geohash string
|
||||
import { collection, query, where, getDocs } from 'firebase/firestore';
|
||||
import { getDb, isFirebaseConfigured } from './config.js';
|
||||
import { getQueryPrefix } from '$lib/utils/geohash.js';
|
||||
|
||||
export async function getNearbyMessages(lat, lng) {
|
||||
const prefix = getQueryPrefix(lat, lng);
|
||||
if (!isFirebaseConfigured()) {
|
||||
console.warn(
|
||||
'Firebase가 설정되지 않아 메시지를 불러오지 못했습니다. 프로젝트 루트에 .env 파일을 추가하세요.'
|
||||
);
|
||||
return [];
|
||||
}
|
||||
|
||||
const q = query(
|
||||
collection(db, 'messages'),
|
||||
where('geohash', '>=', prefix),
|
||||
where('geohash', '<', prefix + 'z')
|
||||
);
|
||||
const prefix = getQueryPrefix(lat, lng);
|
||||
const db = getDb();
|
||||
|
||||
const snapshot = await getDocs(q);
|
||||
return snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
|
||||
}
|
||||
const q = query(
|
||||
collection(db, 'messages'),
|
||||
where('geohash', '>=', prefix),
|
||||
where('geohash', '<', prefix + 'z')
|
||||
);
|
||||
|
||||
const snapshot = await getDocs(q);
|
||||
return snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user