geohash and message query stuff

This commit is contained in:
2026-06-05 21:09:34 +09:00
parent d5ddff9912
commit 8dcdd7a0e4
6 changed files with 1106 additions and 15 deletions

View File

@@ -0,0 +1,16 @@
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
export async function getNearbyMessages(lat, lng) {
const prefix = getQueryPrefix(lat, lng);
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() }));
}