Skip to content

HeartbeatEvent

export interface HeartbeatEvent {

Periodic heartbeat delivered to BackgroundGeolocation.onHeartbeat.

The SDK fires this event on a fixed interval while running in the background, providing a regular opportunity to perform work even when no location events are occurring. Configure the interval with AppConfig.heartbeatInterval.

BackgroundGeolocation.onHeartbeat(async (event) => {
  console.log("[onHeartbeat]", event.location);

  // Request a fresh location fix if needed.
  const location = await BackgroundGeolocation.getCurrentPosition({
    samples: 1
  });
  console.log("[onHeartbeat] fresh position:", location);
});

Members

location

location:Location;

Most recent location recorded by the SDK.

The heartbeat event does not actively request a fresh location fix. Call BackgroundGeolocation.getCurrentPosition if an up-to-date reading is required.