Record Class GeolocationOptions

java.lang.Object
java.lang.Record
com.vaadin.flow.component.geolocation.GeolocationOptions
Record Components:
enableHighAccuracy - when true, asks the browser for the most accurate reading it can produce (typically GPS on mobile devices). This may use more battery and take longer. When null, the browser default (false) applies and a coarse network-based reading is returned
timeout - the maximum time in milliseconds the browser is allowed to spend before reporting a GeolocationErrorCode.TIMEOUT error. When null, there is no timeout — the request will wait indefinitely for a positioning answer
maximumAge - the maximum age in milliseconds of a cached reading that the browser is allowed to return without querying the positioning hardware again. 0 means "never use a cached reading"; null also means 0. 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.get(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationOutcome>) or Geolocation.track(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.

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:
  • Constructor Details

    • GeolocationOptions

      public GeolocationOptions(@Nullable Boolean enableHighAccuracy, @Nullable Integer timeout, @Nullable Integer maximumAge)
      Canonical constructor. Rejects negative timeout and maximumAge values — both must be non-negative or null.
      Parameters:
      enableHighAccuracy - see the record component
      timeout - see the record component
      maximumAge - see the record component
      Throws:
      IllegalArgumentException - if timeout or maximumAge is negative
  • Method Details

    • builder

      public static GeolocationOptions.Builder builder()
      Starts building a GeolocationOptions instance. Only the settings the caller explicitly sets are included; everything else falls back to the browser default.
      Returns:
      a fresh builder
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • enableHighAccuracy

      public @Nullable Boolean enableHighAccuracy()
      Returns the value of the enableHighAccuracy record component.
      Returns:
      the value of the enableHighAccuracy record component
    • timeout

      public @Nullable Integer timeout()
      Returns the value of the timeout record component.
      Returns:
      the value of the timeout record component
    • maximumAge

      public @Nullable Integer maximumAge()
      Returns the value of the maximumAge record component.
      Returns:
      the value of the maximumAge record component