Class GeolocationOptions.Builder
java.lang.Object
com.vaadin.flow.component.geolocation.GeolocationOptions.Builder
- All Implemented Interfaces:
Serializable
- Enclosing class:
GeolocationOptions
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 Summary
Modifier and TypeMethodDescriptionbuild()Creates a newGeolocationOptionsfrom this builder's current state.highAccuracy(boolean highAccuracy) Requests the most accurate reading the device can produce (typically GPS on mobile, coarse network lookup on desktop).maximumAge(int maximumAgeMillis) Sets how old a cached reading may be, in milliseconds.maximumAge(@Nullable Duration maximumAge) Sets how old a cached reading may be while still being acceptable as an answer to this request.timeout(int timeoutMillis) Sets the maximum time in milliseconds to wait for a position before the request fails withGeolocationErrorCode.TIMEOUT.Sets the maximum time to wait for a position before the request fails withGeolocationErrorCode.TIMEOUT.
-
Method Details
-
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-trueto ask for the best available accuracy- Returns:
- this builder
-
timeout
Sets the maximum time to wait for a position before the request fails withGeolocationErrorCode.TIMEOUT. Ifnullis passed (or this setter is never called), the browser waits indefinitely.- Parameters:
timeout- the timeout, ornullto wait indefinitely- Returns:
- this builder
-
timeout
Sets the maximum time in milliseconds to wait for a position before the request fails withGeolocationErrorCode.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- iftimeoutMillisis negative
-
maximumAge
Sets how old a cached reading may be while still being acceptable as an answer to this request.Duration.ZERO(ornull, 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, ornullto refuse cached readings- Returns:
- this builder
-
maximumAge
Sets how old a cached reading may be, in milliseconds. Convenience overload for callers that already have a millisecond value on hand.0means 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- ifmaximumAgeMillisis negative
-
build
Creates a newGeolocationOptionsfrom this builder's current state.- Returns:
- a new options instance
-