New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

capacitor-background-geolocation

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-background-geolocation

A native plugin to get geolocation updates also when app is in background

latest
Source
npmnpm
Version
0.1.8
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Capacitor Background Geolocation

capacitor-background-geolocation

Capacitor plugin for enabling background geolocation service

npm version NPM Publish

Maintainers

MaintainerGitHub
Damiano Brunoriseididieci

Notice 🚀

This plugin actually works only in android. It creates a foreground service (with a notification on android) to keep your app getting location updates.

Installation

Using npm:

npm install capacitor-background-geolocation

Sync native files:

npx cap sync

API

methodinfoplatform
initializeinitialize/start service and configureweb/android
startstarts the service getting location updatesweb/android
stopstops the service getting location updatesweb/android
goForegroundbring the service on foreground (showing a notification)android
stopForegroundbring the service back to the bacgroundandroid

Usage steps (TypeScript)

Import plugin and types

import { Plugins } from '@capacitor/core';
const { BackgroundGeolocation } = Plugins;

import {
  BgLocationEvent,
  BgGeolocationAccuracy,
} from 'capacitor-background-geolocation';

Add listner(s) for location updates

BackgroundGeolocation.addListener('onLocation', (location: BgLocationEvent) => {
  console.log('Got new location', location);
  // Put your logic here.
});

Start getting location updata after user accept permissions

BackgroundGeolocation.addListener('onPermissions', (data: BgPermissions) => {
  console.log('BGLocation permissions:', location);

  // Start geolocation if user grnated permisiions
  if (data.fineLocation)
    BackgroundGeolocation.start();
});

Initialize the plugin settings (required)

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,
});

Request permissions to user

// After user accept permissions the handler above will start the service
BackgroundGeolocation.requestPermissions();

Evnetually stop getting location updates when done

BackgroundGeolocation.stop();

Control background/foreground behaviour

// 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.

Android

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.xml should be automaticcaly filled with the right permissions through a cap sync command but sometimes it doesn't...
Check that there are FOREGROUND_SERVICE and ACCESS_FINE_LOCATION permissions. in your App Manifest.

iOS

This plugin is not yet implemented iOS side, if someone wants to help I will appreciate it...

License

capacitor-background-geolocation is 100% free and open-source, under the MIT license. Use it however you want.

Keywords

capacitor

FAQs

Package last updated on 30 Jul 2021

Did you know?

Socket

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.

Install

Related posts