Skip to content
Support the creatorSupport

Events

Each on… function takes a callback and returns a Subscription. Call remove() when you are done.

useEffect(() => {
const sub = LongPing.onLocation((location) => setLast(location));
return () => sub.remove();
}, []);
Function Native name Payload Fires when
onLocation location Location A fix is recorded (any event type).
onMotionChange motionchange { isMoving, location } The device switches between moving and parked.
onHttp http { status, ok, count, responseText } After every upload attempt.
onProviderChange providerchange ProviderState Anything in the provider state changes: location services, permission, precise/reduced accuracy, power-save mode.
onAuthorization authorization { status, error } An upload got 401/403 and the token could not be refreshed.
onEnabledChange enabledchange { enabled } Tracking was started or stopped, including by long_ping.stop.
onConfigChange configchange Resolved Config A remote config from an upload reply was applied.
onError error { code, message } Location errors, and start failures in the background.
interface MotionChangeEvent {
isMoving: boolean;
location: Location;
}
interface HttpEvent {
status: number; // 0 = network error or timeout
ok: boolean;
count: number; // records in the request
responseText: string; // first 2 KB of the response body
}
interface AuthorizationEvent {
status: number; // the HTTP status that failed (401 or 403)
error: string | null;
}
interface EnabledChangeEvent {
enabled: boolean;
}
interface ErrorEvent {
code: ErrorCode; // see Error codes
message: string;
}

onConfigChange receives the full resolved config (ResolvedConfig), not just the part that changed.