Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda