Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!