Record Class GeolocationOptions
java.lang.Object
java.lang.Record
com.vaadin.flow.component.geolocation.GeolocationOptions
- Record Components:
enableHighAccuracy- whentrue, asks the browser for the most accurate reading it can produce (typically GPS on mobile devices). This may use more battery and take longer. Whennull, the browser default (false) applies and a coarse network-based reading is returnedtimeout- the maximum time in milliseconds the browser is allowed to spend before reporting aGeolocationErrorCode.TIMEOUTerror. Whennull, there is no timeout — the request will wait indefinitely for a positioning answermaximumAge- the maximum age in milliseconds of a cached reading that the browser is allowed to return without querying the positioning hardware again.0means "never use a cached reading";nullalso means0. Larger values save battery and return faster at the cost of freshness
- All Implemented Interfaces:
Serializable
public record GeolocationOptions(@Nullable Boolean enableHighAccuracy, @Nullable Integer timeout, @Nullable Integer maximumAge)
extends Record
implements Serializable
Tuning knobs for a geolocation request — controls the accuracy / battery /
speed / freshness trade-off of a single
Geolocation.getPosition(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationPosition>, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationError>) or
Geolocation.watchPosition(com.vaadin.flow.component.Component) call.
Every field is optional. A null field means "let the browser decide":
high accuracy defaults to false, timeout defaults to no timeout at
all, and cached readings are never accepted unless explicitly allowed. An
instance with no fields set (GeolocationOptions.builder().build())
therefore represents the browser defaults; the Geolocation overloads
that take no options argument use the same instance internally.
Hand-written code should use builder() rather than the canonical
constructor: the builder labels each setting at the call site and accepts
Duration instead of raw milliseconds.
// High accuracy, give up after 10 seconds, refuse cached readings:
GeolocationOptions opts = GeolocationOptions.builder().highAccuracy(true)
.timeout(Duration.ofSeconds(10)).maximumAge(Duration.ZERO).build();
// Low-battery mode: accept a cached reading up to five minutes old:
GeolocationOptions cached = GeolocationOptions.builder()
.maximumAge(Duration.ofMinutes(5)).build();
The canonical record constructor accepts raw millisecond values and is mainly
useful when building an instance from deserialised data.- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionGeolocationOptions(@Nullable Boolean enableHighAccuracy, @Nullable Integer timeout, @Nullable Integer maximumAge) Canonical constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic GeolocationOptions.Builderbuilder()Starts building aGeolocationOptionsinstance.@Nullable BooleanReturns the value of theenableHighAccuracyrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@Nullable IntegerReturns the value of themaximumAgerecord component.@Nullable Integertimeout()Returns the value of thetimeoutrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
GeolocationOptions
public GeolocationOptions(@Nullable Boolean enableHighAccuracy, @Nullable Integer timeout, @Nullable Integer maximumAge) Canonical constructor. Rejects negativetimeoutandmaximumAgevalues — both must be non-negative ornull.- Parameters:
enableHighAccuracy- see the record componenttimeout- see the record componentmaximumAge- see the record component- Throws:
IllegalArgumentException- iftimeoutormaximumAgeis negative
-
-
Method Details
-
builder
Starts building aGeolocationOptionsinstance. Only the settings the caller explicitly sets are included; everything else falls back to the browser default.- Returns:
- a fresh builder
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
enableHighAccuracy
Returns the value of theenableHighAccuracyrecord component.- Returns:
- the value of the
enableHighAccuracyrecord component
-
timeout
Returns the value of thetimeoutrecord component.- Returns:
- the value of the
timeoutrecord component
-
maximumAge
Returns the value of themaximumAgerecord component.- Returns:
- the value of the
maximumAgerecord component
-