8000 GitHub - yusufokkabas/foreground-location: A Capacitor plugin for tracking location in the foreground and sending it to a server.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

yusufokkabas/foreground-location

Repository files navigation

Foreground Location

A Capacitor plugin for tracking location in the foreground and sending it to a server.

Installation

npm install foreground-location
npx cap sync

Android Configuration

This plugin requires the following permissions in your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- Add the foreground service declaration -->
<service
    android:name=".plugins.foregroundlocation.ForegroundLocationService"
    android:enabled="true"
    android:exported="false"
    android:foregroundServiceType="location" />

Usage

NOTE: This plugin is written for testing purposes in line with my needs and currently only works with esri services. The service to be opened on the Esri side; Fields: objectid ( type: esriFieldTypeOID) x ( type: esriFieldTypeDouble ) y ( type: esriFieldTypeDouble) time ( type: esriFieldTypeDate) username ( type: esriFieldTypeString) and must be taking Point.

NOTE: The implementation working only android. Development required for iOS part.

import { ForegroundLocation } from 'foreground-location';

// Start the location service
async function startLocationTracking() {
  try {
    const result = await ForegroundLocation.startLocationService({
      serverUrl: 'https://your-api.com/location',
      accessToken: 'your-access-token',
      updateInterval: 5000 // Optional, defaults to 5000ms (5 seconds)
    });
    
    console.log('Location tracking started:', result.message);
  } catch (error) {
    console.error('Error starting location tracking:', error);
  }
}

// Stop the location service
async function stopLocationTracking() {
  try {
    const result = await ForegroundLocation.stopLocationService();
    console.log('Location tracking stopped:', result.message);
  } catch (error) {
    console.error('Error stopping location tracking:', error);
  }
}

API

echo(...)

echo(options: { value: string }) => Promise<{ value: string }>
Param Type
options { value: string }

Returns: Promise<{ value: string }>


startLocationService(...)

startLocationService(options: { serverUrl: string; accessToken: string; updateInterval?: number; }) => Promise<{ success: boolean; message: string; }>

Starts the foreground location service

Param Type Description
options { serverUrl: string; accessToken: string; updateInterval?: number; } The server URL, access token, and update interval

Returns: Promise<{ success: boolean; message: string; }>


stopLocationService()

stopLocationService() => Promise<{ success: boolean; message: string; }>

Stops the foreground location service

Returns: Promise<{ success: boolean; message: string; }>


License

MIT

About

A Capacitor plugin for tracking location in the foreground and sending it to a server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0