react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Receive background location updates only when the app is open or minimized.
import BackgroundFetch from 'react-native-background-fetch'; import BackgroundGeolocation from 'react-native-background-geolocation'; import { Alert } from "react-native";
export const initBackgroundFetch = async () => {
BackgroundGeolocation.onLocation(location => {
Alert.alert(location.toString());
console.log("[location] ", location);
}, error => {
console.log("[location] ERROR: ", error);
});
// This handler fires when movement states changes (stationary->moving; moving->stationary)
BackgroundGeolocation.onMotionChange(location => {
Alert.alert(location.toString());
console.log("[motionchange] ", location);
});
// This handler fires on HTTP responses
BackgroundGeolocation.onHttp(response => {
console.log("[http] ", response);
});
// This event fires when a change in motion activity is detected
BackgroundGeolocation.onActivityChange(activityEvent => {
console.log("[activitychange] ", activityEvent);
});
// This event fires when the user toggles location-services authorization
BackgroundGeolocation.onProviderChange(providerEvent => {
console.log("[providerchange] ", providerEvent);
});
////
// 2. Execute #ready method (required)
//
BackgroundGeolocation.ready({
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 1,
// Application config
debug: true, // <-- enable this hear debug sounds.
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when app terminated.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
// HTTP / SQLite config
url: "http://yourserver.com/locations",
batchSync: false, // <-- Set true to sync locations to server in a single HTTP request.
autoSync: true, // <-- Set true to sync each location to server as it arrives.
headers: { // <-- Optional HTTP headers
"X-FOO": "bar"
},
params: { // <-- Optional HTTP params
"auth_token": "maybe_your_server_authenticates_via_token_YES?"
}
}, (state) => {
console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
if (!state.enabled) {
////
// 3. Start tracking!
//
BackgroundGeolocation.start(function () {
console.log("- Start success");
});
}
});
};
How can i Receive background location updates only when the app is open or minimized How can i remove notifications related to background location updates. please help me on this
Remove notifications related to background location updates.
I don't know what you're talking about talking about. I don't understand your need.
I am getting notifications when we are moving and Start tracking like. I don't want notifcations. and please check above code is that correct or not?
Read the wiki "Debugging" and "Philosophy of Operation". Also consult the api docs linked at the top of the readme.
I am getting push notifications for the gps. i am taking about that
Read the wiki "Debugging" and learn about the config options you're using by reading the api docs.
Those are not Push notifications, they're local notifications to assist you during development and field-testing so you can see it working in real time. Search the api docs Config.debug.
import BackgroundFetch from 'react-native-background-fetch'; import BackgroundGeolocation from 'react-native-background-geolocation'; import { Alert } from "react-native";
export const initBackgroundFetch = async () => {
BackgroundGeolocation.onLocation(location => { Alert.alert(location.toString()); console.log("[location] ", location); }, error => { console.log("[location] ERROR: ", error); }); // This handler fires when movement states changes (stationary->moving; moving->stationary) BackgroundGeolocation.onMotionChange(location => { Alert.alert(location.toString()); console.log("[motionchange] ", location); }); // This handler fires on HTTP responses BackgroundGeolocation.onHttp(response => { console.log("[http] ", response); }); // This event fires when a change in motion activity is detected BackgroundGeolocation.onActivityChange(activityEvent => { console.log("[activitychange] ", activityEvent); }); // This event fires when the user toggles location-services authorization BackgroundGeolocation.onProviderChange(providerEvent => { console.log("[providerchange] ", providerEvent); }); //// // 2. Execute #ready method (required) // BackgroundGeolocation.ready({ // Geolocation Config desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 10, // Activity Recognition stopTimeout: 1, // Application config debug: true, // <-- enable this hear debug sounds. logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, stopOnTerminate: false, // <-- Allow the background-service to continue tracking when app terminated. startOnBoot: true, // <-- Auto start tracking when device is powered-up. // HTTP / SQLite config url: "http://yourserver.com/locations", batchSync: false, // <-- Set true to sync locations to server in a single HTTP request. autoSync: true, // <-- Set true to sync each location to server as it arrives. headers: { // <-- Optional HTTP headers "X-FOO": "bar" }, params: { // <-- Optional HTTP params "auth_token": "maybe_your_server_authenticates_via_token_YES?" } }, (state) => { console.log("- BackgroundGeolocation is configured and ready: ", state.enabled); if (!state.enabled) { //// // 3. Start tracking! // BackgroundGeolocation.start(function () { console.log("- Start success"); }); } });};
How can i Receive background location updates only when the app is open or minimized How can i remove notifications related to background location updates. please help me on this
This is in Separate page and i want to get location latitude and longitude in another pages How can i do that.
2024-01-09 15:29:38.723546+0530 Verifuel[631:72991] ℹ️-[TSLocationManager on:success:failure:] location 2024-01-09 15:29:38.726334+0530 Verifuel[631:72550] ℹ️-[TSLocationManager on:success:failure:] motionchange 2024-01-09 15:29:38.738456+0530 Verifuel[631:72550] ℹ️-[TSLocationManager on:success:failure:] activitychange 2024-01-09 15:29:38.740349+0530 Verifuel[631:72990] ℹ️-[TSLocationManager on:success:failure:] heartbeat 2024-01-09 15:29:38.740744+0530 Verifuel[631:72550] ℹ️-[TSGeofenceManager onGeofence:] 2024-01-09 15:29:38.743349+0530 Verifuel[631:72990] ℹ️-[TSGeofenceManager onGeofencesChange:] 2024-01-09 15:29:38.744658+0530 Verifuel[631:72550] ℹ️-[TSLocationManager on:success:failure:] http 2024-01-09 15:29:38.744725+0530 Verifuel[631:72990] ℹ️-[TSLocationManager on:success:failure:] providerchange
if there's a specific part of your code that you suspect might be causing the issue, please share that part as well. This will help me provide more accurate assistance in identifying and resolving the problem
The plug-in is event-based. There are 13 total events you can register listeners for including .onLocation.
Read the api docs about all 13 events you can register.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.