Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
How to perform a POST request using background task for React Native apps using expo

I am trying to log my GPS coordinates in a React-Native expo application.

The background task runs successfully and consoles log the coordinates.

Now I want to send them to my server.

For example a post request to /api/mylocation?lon=123&lat=345

I tried a regular fetch method but I get a timeout error.

regular meaning fetch(url,{ method:'POST' etc}) (I know how to perform a basic fetch)

How can I solve this? I suspect it has to do with async and all that.

  const LOCATION_TRACKING = 'location-tracking';

  const startLocationTracking = async () => {
    console.log('startLocationTracking');
    await Location.startLocationUpdatesAsync(LOCATION_TRACKING, {
      accuracy: Location.Accuracy.Highest,
      timeInterval: 10000,
      distanceInterval: 0,
    });
    const hasStarted = await Location.hasStartedLocationUpdatesAsync(
      LOCATION_TRACKING
    );
    console.log('tracking started?', hasStarted);
  };
  


  TaskManager.defineTask(LOCATION_TRACKING, async ({ data, error }) => {
    console.log('running task:', data, error);
    // send_driver_location()

    if (error) {
      console.log('LOCATION_TRACKING task ERROR:', error);
      return;
    }
    if (data) {
      const { locations } = data;
      let lat = locations[0].coords.latitude;
      let long = locations[0].coords.longitude;
  
      console.log(
        `${new Date(Date.now()).toLocaleString()}: ${lat},${long}`

      );



      // add a fetch method here? 

      // fetch(url, {...}


    }
  });

Obviously, this will be helpful when I want to fetch tokens from my server for authentication purposes also.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda