In Node.js, I would recommend using firestore with geofirex, so you can search within a certain radius, and thanks to firebase functions, you can even create real-time queries.
I made this web app that shows only points within a radius.
The main functions to store and read values are like this:
Reading
const DEFAULT_POINT = geo.point(32.520666, -117.021315);
const opinions = db.collection('opinions');
const opinionsSubscribe = () => {
// Here we check opinions within 22km of radius
// 'position' is the field where we store our geofirex point
const query = reports.within(DEFAULT_POINT, 22, 'position');
// This pipe just parse the data to geojson to make it easy to render directly on a map (tested with google and esri)
const obs = query.pipe(toGeoJSON('position', true));
obs.subscribe((geoj) => {
console.log('reports changed');
mainReportsData.geo = geoj;
io.emit('reports', {
metric: mainReportsData.geo,
});
});
};
opinionsSubscribe();
Writing
const storeOpinion = (uid, info, res) => {
const {
address,
latitude,
longitude,
opinion,
} = info;
const lat = parseFloat(latitude);
const lon = parseFloat(longitude);
const timestamp = admin.firestore.FieldValue.serverTimestamp();
// We use default firestore add function, so we need to extract the data from geofirex GeoPoint function
const { data } = geo.point(lat, lon);
// The attribute that stores entry location
const position = {
geopoint: new admin.firestore.GeoPoint(lat, lon),
geohash: data.geohash,
};
opinions.add({
address,
timestamp,
user: uid,
position,
})
.then(() => {
res.send({ data: 'success' });
})
.catch(() => {
res.send({ data: 'error' });
});
};
You can explore the code from this project, is almost the same code, feel free to ask any question.