Giter Club home page Giter Club logo

Comments (13)

christocracy avatar christocracy commented on August 23, 2024

Do you know you need to travel at least 200 meters before tracking engages? You need to go outside and move.

from react-native-background-geolocation.

renangc90 avatar renangc90 commented on August 23, 2024

Yes, I walked 5000 meters and it didn't send data to Firebase

from react-native-background-geolocation.

christocracy avatar christocracy commented on August 23, 2024

I’m not concerned about your Firebase. Does the plug-in make debug sound FX?

learn to fetch and analyze the plug-in logs. See wiki “Debugging”. Search api docs “emailLog”

from react-native-background-geolocation.

renangc90 avatar renangc90 commented on August 23, 2024

Issued, is it not compatible with realtime firebase?

from react-native-background-geolocation.

christocracy avatar christocracy commented on August 23, 2024

You’re responsible for your own JavaScript code implementing Firebase. That’s not the plug-ins responsibility.

im only concerned with “does the plugin track location and emit debug soundFX.

from react-native-background-geolocation.

christocracy avatar christocracy commented on August 23, 2024

Please learn to syntax highlight codeblocks:
https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#fenced-code-blocks

from react-native-background-geolocation.

renangc90 avatar renangc90 commented on August 23, 2024
BackgroundGeolocation.ready({
      // Geolocation Config
      backgroundPermissionRationale: {
        title: 'Permitir acesso à sua localização em background',
        message:
          'Para obter sua localização com precisão, por favor permita que o App obtenha sua localização o tempo todo.',
        positiveAction: 'Configurar',
        negativeAction: 'Cancelar',
      },
      locationAuthorizationAlert: {
        titleWhenOff: 'Localização indisponível',
        titleWhenNotEnabled: 'Localização em background indisponível',
        instructions:
          'Para obter sua localização com precisão, por favor permita que o App obtenha sua localização o tempo todo.',
        settingsButton: 'Configurar',
        cancelButton: 'Cancelar',
      },
      notification: {
        title: 'Acompanhando sua localização',
        text: 'Acompanhamos sua localização para enviar corridas próximas e monitorar a entrega.',
      },
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      // Activity Recognition
      stopTimeout: 5,
      // Application config
      debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
      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.
      // HTTP / SQLite config
      url: 'https://shark-app-j3vbs.ondigitalocean.app/geolocationbackground',
      batchSync: false,       // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
      autoSync: true,         // <-- [Default: true] Set true to sync each location to server as it arrives.
      headers: {              // <-- Optional HTTP headers
        // "X-FOO": "bar"
        "Authorization": `Bearer ${prestador.token}`
      },
      params: {               // <-- Optional HTTP params
        // "auth_token": "maybe_your_server_authenticates_via_token_YES?"
        "prestador_id": prestador.id,
        "nome": prestador.nome,
        "genero": prestador.genero,
        "foto_perfil": prestador.foto_perfil,
        "prestadorsubcategoria": prestador.prestadorsubcategoria
      }
    }).then((state) => {
      setEnabled(state.enabled)
      console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
    });

Do I need to do something special to send the parameters? It's only arriving with the screen on.

from react-native-background-geolocation.

christocracy avatar christocracy commented on August 23, 2024

See api docs .emailLog. Learn to fetch and observe the plug-in logs.

and get rid of this: you do NOT need to do this.

if (error.message === "Waiting for previous start action to complete") {
          BackgroundGeolocation.stop().then(() => {
            console.log("BackgroundGeolocation stopped, restarting...");
            BackgroundGeolocation.start().then(() => {
              console.log("BackgroundGeolocation restarted");
            }).catch(error => {
              console.error("Error restarting BackgroundGeolocation: ", error);
            });
          }).catch(stopError => {
            console.error("Error stopping BackgroundGeolocation: ", stopError);
          });
        } else {
          console.error("Error starting BackgroundGeolocation: ", error);
        }

from react-native-background-geolocation.

renangc90 avatar renangc90 commented on August 23, 2024
import React, { useContext } from 'react';
import { Switch, Text, View, PermissionsAndroid } from 'react-native';
import BackgroundGeolocation from "react-native-background-geolocation";
import { AuthContext } from '../../contexts/AuthContext';
import api from '../../services/api';

const HelloWorld = () => {
  const [enabled, setEnabled] = React.useState(false);
  const [location, setLocation] = React.useState('');

  const { prestador } = useContext(AuthContext);

  React.useEffect(() => {
    const requestLocationPermissions = async () => {
      try {
        const granted = await PermissionsAndroid.requestMultiple([
          PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
          PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
          PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
        ]);

        if (
          granted['android.permission.ACCESS_FINE_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED &&
          granted['android.permission.ACCESS_COARSE_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED &&
          granted['android.permission.ACCESS_BACKGROUND_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED
        ) {
          console.log('Você tem todas as permissões de localização');
        } else {
          console.log('Permissões de localização negadas');
        }
      } catch (err) {
        console.warn(err);
      }
    };

    requestLocationPermissions();

    const onLocation = BackgroundGeolocation.onLocation(async (location) => {
      console.log('[onLocation]', location);
      setLocation(JSON.stringify(location, null, 2));

      let dados = {
        "prestador_id": prestador.id,
        "nome": prestador.nome,
        "genero": prestador.genero,
        "foto_perfil": prestador.foto_perfil,
        "prestadorsubcategoria": prestador.prestadorsubcategoria,
        "location": {
          "coords": {
            "latitude": location.coords.latitude,
            "longitude": location.coords.longitude,
          }
        }
      };
      
      try {
        const response = await api.post('/geolocationbackground/', dados, {
          headers: {
            'Authorization': `Bearer ${prestador.token}`
          }
        });
        console.log('Post successful: ', response.data);
      } catch (error) {
        console.error('Post failed: ', error);
      }
    });

    const onMotionChange = BackgroundGeolocation.onMotionChange((event) => {
      console.log('[onMotionChange]', event);
    });

    const onActivityChange = BackgroundGeolocation.onActivityChange((event) => {
      console.log('[onActivityChange]', event);
    });

    const onProviderChange = BackgroundGeolocation.onProviderChange((event) => {
      console.log('[onProviderChange]', event);
    });

    BackgroundGeolocation.ready({
      backgroundPermissionRationale: {
        title: 'Permitir acesso à sua localização em background',
        message: 'Para obter sua localização com precisão, por favor permita que o App obtenha sua localização o tempo todo.',
        positiveAction: 'Configurar',
        negativeAction: 'Cancelar',
      },
      locationAuthorizationAlert: {
        titleWhenOff: 'Localização indisponível',
        titleWhenNotEnabled: 'Localização em background indisponível',
        instructions: 'Para obter sua localização com precisão, por favor permita que o App obtenha sua localização o tempo todo.',
        settingsButton: 'Configurar',
        cancelButton: 'Cancelar',
      },
      notification: {
        title: 'Acompanhando sua localização',
        text: 'Acompanhamos sua localização para enviar corridas próximas e monitorar a entrega.',
      },
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      stopTimeout: 5,
      debug: true,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      stopOnTerminate: false,
      startOnBoot: true,
      url: 'https://shark-app-j3vbs.ondigitalocean.app/geolocationbackground',
      batchSync: false,
      autoSync: true,
      headers: {
        "Authorization": `Bearer ${prestador.token}`
      },
      params: {
        "prestador_id": prestador.id,
        "nome": prestador.nome,
        "genero": prestador.genero,
        "foto_perfil": prestador.foto_perfil,
        "prestadorsubcategoria": prestador.prestadorsubcategoria
      }
    }).then((state) => {
      setEnabled(state.enabled);
      console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);

      let Logger = BackgroundGeolocation.logger;
      Logger.emailLog('[email protected]')
        .then(success => {
          console.log(success, '[emailLog] success');
        })
        .catch(error => {
          console.log('[emailLog] FAILURE: ', error);
        });
    });

    return () => {
      onLocation.remove();
      onMotionChange.remove();
      onActivityChange.remove();
      onProviderChange.remove();
    };
  }, []);

  React.useEffect(() => {
    if (enabled) {
      BackgroundGeolocation.start();
    } else {
      BackgroundGeolocation.stop();
      setLocation('');
    }
  }, [enabled]);

  return (
    <View style={{ alignItems: 'center' }}>
      <Text>Click to enable BackgroundGeolocation</Text>
      <Switch value={enabled} onValueChange={setEnabled} />
      <Text style={{ fontFamily: 'monospace', fontSize: 12 }}>{location}</Text>
    </View>
  );
};

export default HelloWorld;

If I give setEnabled true in the Android emulator, it saves a post record on my server, but using the debug apk, if I enable it, nothing happens, that's all that's needed for it to work.

from react-native-background-geolocation.

christocracy avatar christocracy commented on August 23, 2024

Are you observing the plug-in logs in adb logcat?

see wiki “Debugging”.

You can’t develop with this plugin without observing the native device logs.

from react-native-background-geolocation.

github-actions avatar github-actions commented on August 23, 2024

This issue is stale because it has been open for 30 days with no activity.

from react-native-background-geolocation.

renangc90 avatar renangc90 commented on August 23, 2024

Even using BackgroundGeolocation.NOTIFICATION_PRIORITY_MIN it still emits sound, could the API not emit any sound at all?

notification: {
                priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_MIN,
                title: 'Acompanhando sua localização',
                text: 'Acompanhamos sua localização para enviar chamados de clientes próximos a você.',
            },

from react-native-background-geolocation.

christocracy avatar christocracy commented on August 23, 2024

See api docs Config.debug

from react-native-background-geolocation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.