Implementing GeoFire functionality in Firebase Cloud Functions and TypeScript

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
    Error: Invalid GeoFire location '40,40': latitude must be a number
    . Even though I'm passing integers without any string literals using Postman.
  • 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?

Answer №1

To transform latitude and longitude into numerical values, you can utilize the Number class.

const latitude = Number(req.query.latitude);
const longitude = Number(req.query.longitude);    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is typescript-eslint flagging the error "Unsafe call of an any typed value" whenever I try to use the delete or update methods?

type TResultCategory<T> = { title: string; items: T[]; description?: string; delete(dispatch: Dispatch<{}>): void; update?(dispatch: Dispatch<{}>, products: TCartProduct[]): void; } type TResult = (TResultCategory<TResultPro ...

Can you use the useCallback function within a nested callback function?

within component A: const retrieveOnClick = useCallback( (rec: GenericRec): (() => void) => () => { setSelectedRecord(rec); }, [], ); inside component B which is a child of A: const displayRecord = useCallback( (row: Row& ...

Specify that a function is adhering to an interface

Is there a way in Typescript to ensure that a function implements a specific interface? For example: import { BrowserEvents, eventHandler, Event } from './browser-events'; export function setup(){ const browserEvents = new BrowserEvents(); b ...

Guide to displaying a nested object in Angular 7

Within my object data, I have a nested structure- "data": { "serial": "123", "def": { "id": "456", "data": { "firstname&q ...

Utilize the dropdown menu across all table cells in a table

My p-table has a unique feature - the last column contains three dots that trigger a dropdown menu when clicked. The only issue is that the fixed position of the dropdown menu does not align properly with the td element in each row. Check out the HTML cod ...

Exploring the Depths of JSON Arrays within Typescript

I am faced with a challenge in extracting the value of the "id" from the following array of JSON data. The issue lies in the fact that the value is enclosed within double square brackets "[[" which are causing complications in retrieving the desired result ...

Kubernetes Cluster Encountering Error with Google FCM Firebase-Admin initializeApp() Function

Currently, I am in the process of setting up a NodeJs server and integrating FCM for push notifications. While everything runs smoothly locally, I encounter an error when running on my K8S cluster. An issue arises with FirebaseAppError: The credential impl ...

The module named "tapable" does not contain an export for the item "Tapable"

While developing a WordPress plugin for a custom Gutenberg block, I encountered a challenge. I needed to incorporate additional scripts in TypeScript and opted to use "$ tsc --watch" along with a "tsconfig.json" file for compilation. Upon installing @word ...

"The act of initializing an EntryComponent in Angular results in the creation of a brand

In my main component, app.component.ts, I have integrated a new service into the providers[] array and initialized it in the constructor: @Component({ selector: 'app-main', templateUrl: './app.component.html', styleUrls: ['. ...

Encountering an error with dynamic routing in Angular 4 when using dynamic components

Upon receiving routing configuration from a server and loading it before the application bootstrap, the config.json file contains the following setup: [{ "path": "dashboard", "component": "SingleComponent", "data": {...} }, { "path": "payment", ...

Sync user information when alterations are made on a different device

As I create a Discord clone using Next.js, I've encountered an issue where when a server is deleted, another client can still see and use the server until the page is reloaded. When testing out the official Discord web app, changes seemed to happen in ...

Guide on creating a typed object variable in Typescript

In my Typescript code, I have an interface called Employees: export interface Employees { [employeeId: string]: { name: string gender: Gender } } I am trying to declare a variable employees that is of type Employees. Here are the attempts I h ...

How to display a modal within a router-link in Vue 3?

Below are buttons with router-links. However, I only want the calculator button to open a modal. When I execute the code provided, all buttons trigger the modal instead of just the calculator button. Output: https://i.sstatic.net/layQ1.png Router-link C ...

Transform the fetch request to utilize oboe for parsing JSON streams in a Typescript environment

I've been working on this fetch call: api<T>(url: string, headers: Request): Promise<T> { return fetch(url, headers) .then(response => { if (!response.ok) { throw new Error(respo ...

Error: The terminal reports that the property 'then' cannot be found on the data type 'false' while trying to compile an Angular application

In my Angular application, which I initiate through the terminal with the command ng serve, I am encountering build errors that are showing in red on the terminal screen. ✔ Compiled successfully. ⠋ Generating browser application bundles... Error: s ...

Is it possible for a voiceover artist to initiate API requests?

As I work on the registration feature of my application, I am faced with the requirement that email addresses must be unique in the database. Since I am responsible for the front-end development, I am considering creating a Value Object (VO) that can make ...

Trouble with Nextjs link not functioning properly with a URL object when incorporating element id into the pathname

Recently I added translations to my website, which means I now need to use a URL object when creating links. Everything has been going smoothly with this change except for one issue: when I try to click a link that points to /#contact. When simply using h ...

Retrieve a specific value from an array within Firestore

I am facing an issue where I can only retrieve the values I need from the array by adding a specific string like "اقلام" or "سبورة". However, I want the value to be passed as a prop from another component or screen. Is there a way to resolve this ...

What sets apart the typescript@latest and typescript@next NPM packages from each other?

Can you enlighten me on the disparities between typescript@next and typescript@latest? I understand the functionality of typescript@next, yet I struggle to differentiate it from typescript@latest. From my perspective, they appear to be identical. There is ...

Typescript error: The property 'set' is not found on type '{}'

Below is the code snippet from my store.tsx file: let store = {}; const globalStore = {}; globalStore.set = (key: string, value: string) => { store = { ...store, [key]: value }; } globalStore.get = (key) => { return store[key]; } export d ...