location.startUpdates
Locates in the background too, delivering fixes to the task name until
stopUpdates(name), across the app's restarts. Needs the location
permission and locationAlways declared (docs/location.md).
Utilisation
Register background updates
import { location, permissions, storage } from 'kuito';
// At module scope: a background launch runs the app's modules, not its UI.
location.defineUpdates('run', async ({ locations }) => {
const track: unknown[] = JSON.parse((await storage.get('track')) ?? '[]');
await storage.set('track', JSON.stringify([...track, ...locations.map((fix) => fix.coords)]));
});
async function startRun() {
const { status } = await permissions.request('locationAlways');
if (status === 'granted')
await location.startUpdates('run', {
accuracy: 'high',
distanceInterval: 10,
notification: { title: 'Recording your run' },
});
}Signatures
(name: string, options?: LocationTaskOptions): Promise<void>Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
name | string | Oui | — |
options | LocationTaskOptions | Non | — Par défaut: {} |
Retourne
Promise<void>
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.