Class GeolocationOptions.Builder

java.lang.Object
com.vaadin.flow.component.geolocation.GeolocationOptions.Builder
All Implemented Interfaces:
Serializable
Enclosing class:
GeolocationOptions

public static final class GeolocationOptions.Builder extends Object implements Serializable
Builder for GeolocationOptions. Accepts Duration for the time-based fields and boolean for the high-accuracy flag so that call sites read naturally. Any setter that is not called leaves the corresponding field null, which means "use the browser default" when the request runs.
See Also:
  • Method Details

    • highAccuracy

      public GeolocationOptions.Builder highAccuracy(boolean highAccuracy)
      Requests the most accurate reading the device can produce (typically GPS on mobile, coarse network lookup on desktop). High accuracy usually costs more battery and takes longer.
      Parameters:
      highAccuracy - true to ask for the best available accuracy
      Returns:
      this builder
    • timeout

      public GeolocationOptions.Builder timeout(@Nullable Duration timeout)
      Sets the maximum time to wait for a position before the request fails with GeolocationErrorCode.TIMEOUT. If null is passed (or this setter is never called), the browser waits indefinitely.
      Parameters:
      timeout - the timeout, or null to wait indefinitely
      Returns:
      this builder
    • timeout

      public GeolocationOptions.Builder timeout(int timeoutMillis)
      Sets the maximum time in milliseconds to wait for a position before the request fails with GeolocationErrorCode.TIMEOUT. Convenience overload for callers that already have a millisecond value on hand.
      Parameters:
      timeoutMillis - the timeout in milliseconds; must be non-negative
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if timeoutMillis is negative
    • maximumAge

      public GeolocationOptions.Builder maximumAge(@Nullable Duration maximumAge)
      Sets how old a cached reading may be while still being acceptable as an answer to this request. Duration.ZERO (or null, or never calling this setter) means the browser must query the positioning hardware on every request. Larger values save battery and return faster.
      Parameters:
      maximumAge - the maximum acceptable age, or null to refuse cached readings
      Returns:
      this builder
    • maximumAge

      public GeolocationOptions.Builder maximumAge(int maximumAgeMillis)
      Sets how old a cached reading may be, in milliseconds. Convenience overload for callers that already have a millisecond value on hand. 0 means the browser must query the positioning hardware on every request.
      Parameters:
      maximumAgeMillis - the maximum acceptable age in milliseconds; must be non-negative
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if maximumAgeMillis is negative
    • build

      public GeolocationOptions build()
      Creates a new GeolocationOptions from this builder's current state.
      Returns:
      a new options instance