Capacitor Support for Background Geolocation

// Old API with optional callbacks as method-arguments is
// no longer supported, eg: methodName(successFn)
// use Promise api, eg: methodName().then(successFn)
// OLD callback args not supported.
BackgroundGeolocation.ready(config, (state) => {
console.log('[ready] state:', state);
});
// NEW: Only Promise API is supported:
BackgroundGeolocation.ready(config).then((state) => {
console.log('[ready] state', state);
});
// Or use await in an async function
const state = await BackgroundGeolocation.ready(config);
console.log('[ready] state', state);
// OLD: callback args not supported.
BackgroundGeolocation.getState((state) => {
console.log('[getState]', state);
});
// NEW: Only Promise API is supported:
BackgroundGeolocation.getState().then((state) => {
console.log('[getState]', state);
});
// Or use await in an async function
const state = await BackgroundGeolocation.getState();
console.log('[getState]', state);
// Adding event-listeners is the same as always:
BackgroundGeolocation.onLocation((location) => {
console.log('[onLocation]', location);
}, (error) => {
console.log('[onLocation] ERROR', error);
});
BackgroundGeolocation.onMotionChange((location) => {
console.log('[onMotionChange]', location);
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store