Class GeolocationTracker

java.lang.Object
com.vaadin.flow.component.geolocation.GeolocationTracker
All Implemented Interfaces:
Serializable

public class GeolocationTracker extends Object implements Serializable
A handle to a geolocation tracking session, returned by 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 Details

    • value

      public Signal<GeolocationResult> 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, call value().get() or value().peek() to read a snapshot.

      The signal starts as GeolocationPending until the first reading arrives, then transitions to GeolocationPosition on every successful reading, or GeolocationError on failure. After stop() (or after the owner detaches), the last value remains readable but the signal stops receiving updates. Calling resume() resumes updates; the signal is reset to GeolocationPending on resume.

      Returns:
      a read-only signal reporting the latest result
    • active

      public Signal<Boolean> active()
      Returns a read-only signal that indicates whether the tracker is currently receiving updates. Flips to true on resume() and to false on stop() (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 call active().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 to value() stay attached and start receiving new updates.

      The signal is reset to GeolocationPending on every resume. Calling resume() 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 with resume().