The issue is that I want a firebase function, in which a geopoint is passed (latitude and longitude) and from this, I find the nearby places that I have in the BBDD.
The only thing I have is this equation:
(lonBD−lonCliente)^2+(latBD−latCliente)^2 < (20Km)^2
Where 20km does not go in km, there are units that are 111 km each. Therefore they are 20/11 = 0'180 period
(lonBD−lonCliente)^2+(latBD−latCliente)^2 < (0'180)^2
The issue is that I do not want to go through all the rows in the database. I think it would be best if this formula were the where
of the query.
But I am unable to find the Math.pow
or how to multiply to build the where in firestore.
For now I have this, which of course, does not work:
module.exports = functions.https.onRequest((req, res) => {
var firestore = admin.firestore();
var latCliente = req.query.lat;
var lonCliente = req.query.lon;
firestore.collection('sitios')
.where("(geo_coor.getLongitude()−lonCliente) * (geo_coor.getLongitude()−lonCliente) + (geo_coor.getLatitude−latCliente) * (geo_coor.getLatitude−latCliente)", "<", 0.03314)
.get()
.then(function(querySnapshot) {
//console.log(querySnapshot.docs[0].data())
res.jsonp(querySnapshot.docs.map(function (documentSnapshot) {
return documentSnapshot.data();
}));
});
});
Thank you very much in advance.