Interface GeolocationResult
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
GeolocationError,GeolocationPending,GeolocationPosition
public sealed interface GeolocationResult
extends Serializable
permits GeolocationPending, GeolocationPosition, GeolocationError
The outcome of a geolocation request — a successful reading, an error, or the
initial "waiting for first reading" state of a tracker.
Passed to Geolocation.get(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationResult>) callbacks and held by the signal exposed by
GeolocationTracker.value(). A GeolocationResult is always
exactly one of three things:
GeolocationPending— the initial state of a newly started tracker, before the browser has reported anything. One-shotGeolocation.get(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationResult>)never resolves to this value.GeolocationPosition— a successful reading.GeolocationError— the browser reported an error.
The sealed interface is designed for exhaustive pattern matching. A
switch covering all three permitted subtypes is guaranteed complete
at compile time — adding a new variant in a future version of Flow would
break existing switches so that callers are forced to decide how to handle
it.
switch (result) {
case GeolocationPending p -> showSpinner();
case GeolocationPosition pos -> map.setCenter(pos.coords());
case GeolocationError err -> showError(err.message());
}