Class GeolocationTracker
- All Implemented Interfaces:
Serializable
Geolocation.track(Component) /
Geolocation.track(Component, GeolocationOptions).
Exposes the latest GeolocationResult as a reactive signal via
value(), and lets the application cancel tracking via
stop() or resume it via resume(). The underlying browser
watch is also cancelled automatically when the owning component detaches, so
most applications never need to call stop() explicitly — it is
provided for "Stop tracking" buttons and similar mid-view cancellation.
A tracker is reusable: after stop() you can call resume()
to resume tracking on the same handle, and any effects or bindings subscribed
to value() continue to work. Bind a toggle button's state to
active() to let the UI react to start/stop without tracking your own
flag.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionactive()Returns a read-only signal that indicates whether the tracker is currently receiving updates.voidresume()Starts, or resumes, the underlying browser watch.voidstop()Cancels the underlying browser watch and tears down the server-side listeners.value()Returns a read-only signal that holds the most recent tracking result.
-
Method Details
-
value
Returns a read-only signal that holds the most recent tracking result.Combine with
Signal.effect(owner, ...)or an attach listener to run code whenever the value changes — the effect re-runs automatically on every update and no manual event-listener bookkeeping is required. Outside an effect, callvalue().get()orvalue().peek()to read a snapshot.The signal starts as
GeolocationPendinguntil the first reading arrives, then transitions toGeolocationPositionon every successful reading, orGeolocationErroron failure. Afterstop()(or after the owner detaches), the last value remains readable but the signal stops receiving updates. Callingresume()resumes updates; the signal is reset toGeolocationPendingon resume.- Returns:
- a read-only signal reporting the latest result
-
active
Returns a read-only signal that indicates whether the tracker is currently receiving updates. Flips totrueonresume()and tofalseonstop()(or when the owner detaches).Subscribe with
Signal.effect(owner, ...)to bind a toggle button's label/state to the tracker without tracking a separate flag, or callactive().peek()for a snapshot.- Returns:
- a read-only signal reporting whether tracking is active
-
resume
public void resume()Starts, or resumes, the underlying browser watch.Called automatically from the constructor so that a freshly created tracker is immediately active. Call again after
stop()to resume tracking on the same handle — any effects or bindings subscribed tovalue()stay attached and start receiving new updates.The signal is reset to
GeolocationPendingon every resume. Callingresume()on an already-running tracker is a no-op. -
stop
public void stop()Cancels the underlying browser watch and tears down the server-side listeners.The browser stops reporting position updates and
value()stops changing. The last value remains readable. This is the way to end tracking from application code (e.g. a "Stop" button) — leaving the view automatically calls this method, so there is no need to call it from a detach listener.Idempotent and always safe: calling it twice, or calling it on a tracker whose owner has already detached, does nothing extra. After
stop()the tracker can be resumed withresume().
-