
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
capacitor-background-geolocation
Advanced tools
A native plugin to get geolocation updates also when app is in background
capacitor-background-geolocation
Capacitor plugin for enabling background geolocation service
| Maintainer | GitHub |
|---|---|
| Damiano Brunori | seididieci |
This plugin actually works only in android. It creates a foreground service (with a notification on android) to keep your app getting location updates.
Using npm:
npm install capacitor-background-geolocation
Sync native files:
npx cap sync
| method | info | platform |
|---|---|---|
initialize | initialize/start service and configure | web/android |
start | starts the service getting location updates | web/android |
stop | stops the service getting location updates | web/android |
goForeground | bring the service on foreground (showing a notification) | android |
stopForeground | bring the service back to the bacground | android |
import { Plugins } from '@capacitor/core';
const { BackgroundGeolocation } = Plugins;
import {
BgLocationEvent,
BgGeolocationAccuracy,
} from 'capacitor-background-geolocation';
BackgroundGeolocation.addListener('onLocation', (location: BgLocationEvent) => {
console.log('Got new location', location);
// Put your logic here.
});
BackgroundGeolocation.addListener('onPermissions', (data: BgPermissions) => {
console.log('BGLocation permissions:', location);
// Start geolocation if user grnated permisiions
if (data.fineLocation)
BackgroundGeolocation.start();
});
BackgroundGeolocation.initialize({
notificationText: 'Your app is running, tap to open.',
notificationTitle: 'App Running',
updateInteval: 10000,
requestedAccuracy: BgGeolocationAccuracy.HIGH_ACCURACY,
// Small icon has to be in 'drawable' resources of your app
// if you does not provide one (or it is not found) a fallback icon will be used.
smallIcon: 'ic_small_icon',
// Start getting location updates right away. You can set this to false or not set at all (se below).
startImmediately: true,
});
// After user accept permissions the handler above will start the service
BackgroundGeolocation.requestPermissions();
BackgroundGeolocation.stop();
// Force the service to run in foreground
// It will show the android notification also when your app is up and running
BackgroundGeolocation.goFroreground();
// Restore the service to run in backgroud/default mode: the android notification will be shown only when your app goes in background.
BackgroundGeolocation.stopForeground();
Keep in mind that the plugin will send the service in the foreground when your APP is going into background until you stop the service or quit the APP.
Notice
Remember to add this plugin to your app main acctivity:
import com.getcapacitor.community.bglocation.BackgroundGeolocation; //.... // Initializes the Bridge this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{ // Additional plugins you've installed go here // <Your other plugins if any> add(BackgroundGeolocation.class); }});The
AndroidManifest.xmlshould be automaticcaly filled with the right permissions through acap synccommand but sometimes it doesn't...
Check that there areFOREGROUND_SERVICEandACCESS_FINE_LOCATIONpermissions. in your App Manifest.
This plugin is not yet implemented iOS side, if someone wants to help I will appreciate it...
capacitor-background-geolocation is 100% free and open-source, under the MIT license. Use it however you want.
FAQs
A native plugin to get geolocation updates also when app is in background
The npm package capacitor-background-geolocation receives a total of 0 weekly downloads. As such, capacitor-background-geolocation popularity was classified as not popular.
We found that capacitor-background-geolocation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.