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

231
Vistas
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
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