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

230
Views
Cómo actualizar la ubicación cada 15 minutos y enviar al servidor después de cerrar la aplicación - react-native

Quiero capturar la ubicación actual cada 15 minutos y enviar esa ubicación al servidor. Usé react-native-background-geolocation . Solo funciona en primer plano para mí, pero no en segundo plano. Aquí está mi código

 const [enabled, setEnabled] = React.useState(true); const [location, setLocation] = React.useState(''); React.useEffect(() => { /// 1. Subscribe to events. const onLocation = BackgroundGeolocation.onLocation(location => { console.log('[onLocation]', location); setLocation(JSON.stringify(location, null, 2)) }); BackgroundGeolocation.ready({ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 10, stopTimeout: 5, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app. startOnBoot: true, // <-- Auto start tracking when device is powered-up. batchSync: false, // <-- [Default: false] Set true to sync locations to server in autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives. headers: { 'X-FOO': 'bar', }, params: { auth_token: 'maybe_your_server_authenticates_via_token_YES?', }, }).then(state => { setEnabled(state.enabled); BackgroundGeolocation.watchPosition( function (location) { console.log('- Watch position: ', location); fetch('https://shopql.herokuapp.com/shop', { method: 'GET', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({location}), }).then(data => { console.log('Api called'); }); }, function (errorCode) { alert('An location error occurred: ' + errorCode); }, { interval: 900000, // <-- retrieve a location every 15 min. }, ); if (!state.enabled) { BackgroundGeolocation.start(function () { console.log('- Start success'); }); } console.log( '- BackgroundGeolocation is configured and ready: ', state.enabled, ); }); return () => { onLocation.remove(); onActivityChange.remove(); onProviderChange.remove(); }; }, []); React.useEffect(() => { if (enabled) { BackgroundGeolocation.stop(); setLocation(''); } }, [enabled]);

Intenté con este código pero este código no funciona para mí. funciona bien en primer plano pero no funciona cuando se cierra la aplicación. Por favor, ayúdenme a actualizar la ubicación actual cuando se cierra la aplicación

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!