forked from 20266142/Overheard
geohash and message query stuff
This commit is contained in:
16
src/lib/Firebase/messages.js
Normal file
16
src/lib/Firebase/messages.js
Normal 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() }));
|
||||
}
|
||||
Reference in New Issue
Block a user