Currently, I am in the process of developing a Firebase Cloud Function that will retrieve locations near a specific geographical point (related query). This function requires two parameters: latitude and longitude.
export const getDrinkingFountains = functions.https.onRequest((req, res) => {
const latitude = req.query.latitude;
const longitude = req.query.longitude;
const ref = admin.database().ref("Fountains");
const geoFire = new GeoFire(ref);
// const keys: Fountain[] = {};
return new Promise(function(resolve, reject) {
const geoQuery = geoFire.query({
center: [latitude, longitude],
radius: 10.0
});
geoQuery.on("key_entered", function(key, location, distance) {
// var fountain: Fountain = {key: key, latitude: location.latitude, longitude: location.longitude, distance: distance};
// keys.push(fountain);
});
geoQuery.on("ready", function() {
resolve(arrayShouldGoHere);
});
});
});
The issue I am encountering includes:
- Having difficulty extracting the latitude and longitude values from the request correctly. GeoFire is showing an error message
. Even though I'm passing integers without any string literals using Postman.Error: Invalid GeoFire location '40,40': latitude must be a number
- I am struggling with creating an array of Fountains due to my lack of familiarity with TypeScript.
Would appreciate any guidance or suggestions regarding this matter?