License sales launch: April 27, 2026 Get notified or view pricing

bglocation

Complete TypeScript API exported by @bglocation/capacitor.

Methods

MethodReturnsDescription
getVersion()Promise<VersionInfo>Get wrapper and native core version information.
checkPermissions()Promise<LocationPermissionStatus>Check current foreground and background permission state.
requestPermissions(options?)Promise<LocationPermissionStatus>Request foreground or background location permissions.
configure(options)Promise<ConfigureResult>Configure tracking before start(); partial updates are merged.
start()Promise<LocationState>Start background location tracking.
stop()Promise<LocationState>Stop background location tracking.
getState()Promise<LocationState>Read the current enabled/tracking state.
getCurrentPosition(options?)Promise<Location>Request a single location update.
addGeofence(geofence)Promise<void>Register one geofence region.
addGeofences({ geofences })Promise<void>Register multiple geofences atomically.
removeGeofence({ identifier })Promise<void>Remove a geofence by identifier.
removeAllGeofences()Promise<void>Clear all geofences.
getGeofences()Promise<{ geofences: Geofence[] }>Return the currently registered geofences.
checkBatteryOptimization()Promise<BatteryWarningEvent>Inspect Android battery optimization state.
requestBatteryOptimization()Promise<BatteryWarningEvent>Open Android battery optimization settings.
removeAllListeners()Promise<void>Remove all active event listeners.

Events

Register via BackgroundLocation.addListener(event, handler).

EventPayloadDescription
onLocationLocationLocation update based on distanceFilter.
onHeartbeatHeartbeatEventPeriodic heartbeat, even when stationary.
onProviderChangeProviderChangeEventGPS/network provider status changed.
onHttpHttpEventNative HTTP POST result.
onDebugDebugEventDebug log message when debug mode is enabled.
onBatteryWarningBatteryWarningEventBattery optimization warning on Android.
onAccuracyWarningAccuracyWarningEventApproximate location warning on iOS 14+.
onMockLocationMockLocationEventMock location detected on Android.
onPermissionRationalePermissionRationaleEventShow a custom rationale before background permission.
onTrialExpiredTrialExpiredEventTrial session ended and tracking stopped automatically.
onGeofenceGeofenceEventGeofence transition: enter, exit, or dwell.

Interfaces

Location

interface Location {
  latitude: number;
  longitude: number;
  accuracy: number;
  speed: number;
  heading: number;
  altitude: number;
  timestamp: number;
  isMoving: boolean;
  isMock: boolean;
  effectiveDistanceFilter?: number;
}

LocationConfig

interface LocationConfig {
  distanceFilter?: number | 'auto';
  desiredAccuracy?: 'high' | 'balanced' | 'low';
  heartbeatInterval?: number;            // seconds (default: 15)
  locationUpdateInterval?: number;       // ms, Android minimum interval
  debug?: boolean;
  debugSounds?: boolean;
  autoDistanceFilter?: AutoDistanceFilterConfig;
  http?: HttpConfig;
  notification?: NotificationConfig;     // Android foreground notification
}

HttpConfig

interface HttpConfig {
  url: string;
  method?: 'POST';
  headers?: Record<string, string>;
  buffer?: {
    maxSize?: number;                   // default: 1000
  };
}

Geofence

interface Geofence {
  identifier: string;
  latitude: number;
  longitude: number;
  radius: number;                        // meters
  notifyOnEntry?: boolean;
  notifyOnExit?: boolean;
  notifyOnDwell?: boolean;
  dwellDelay?: number;                   // seconds
  extras?: Record<string, string>;
}

GeofenceEvent

interface GeofenceEvent {
  identifier: string;
  action: 'enter' | 'exit' | 'dwell';
  location: Location | null;
  extras?: Record<string, string>;
  timestamp: number;
}

ConfigureResult

interface ConfigureResult {
  licenseMode: 'full' | 'trial';
  distanceFilterMode: 'fixed' | 'auto';
  licenseUpdatesUntil?: string;
  licenseUpdateExpired?: boolean;
  licenseError?: string;
}

HeartbeatEvent

interface HeartbeatEvent {
  location: Location | null;
  timestamp: number;
}

HttpEvent

interface HttpEvent {
  success: boolean;
  statusCode: number;
  error?: string;
  bufferedCount?: number;
  timestamp: number;
}

Error Codes

CodeDescription
NOT_CONFIGUREDconfigure() must be called before this method.
GEOFENCE_LIMIT_EXCEEDEDMaximum of 20 geofence regions reached.
GEOFENCE_ERRORNative geofence registration failed.
UNSUPPORTEDOperation not supported on the current platform.
TRIAL_COOLDOWNTrial cooldown period is active.
PERMISSION_DENIEDRequired location permissions not granted.