Interface GeolocationResult
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
GeolocationOutcome
- All Known Implementing Classes:
GeolocationError,GeolocationPending,GeolocationPosition
public sealed interface GeolocationResult
extends Serializable
permits GeolocationOutcome, GeolocationPending
Anything a tracker can currently hold — a successful reading, an error, or
the initial "waiting for first reading" state.
Held by the signal exposed by GeolocationTracker.valueSignal(). A
GeolocationResult is always exactly one of three things:
GeolocationPending— the initial state of a newly started tracker, before the browser has reported anything.GeolocationPosition— a successful reading.GeolocationError— the browser reported an error.
Geolocation.get(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationPosition>, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationError>) requests never produce
GeolocationPending; they deliver the position and the error through
separate callbacks instead.
The sealed hierarchy is designed for exhaustive pattern matching. A
switch covering the three permitted variants is guaranteed complete
at compile time.
switch (tracker.valueSignal().get()) {
case GeolocationPending p -> showSpinner();
case GeolocationPosition pos -> map.setCenter(pos.coords());
case GeolocationError err -> showError(err.message());
}