Class GeolocationOptions
- All Implemented Interfaces:
Jsonable
This class mirrors the browser's PositionOptions interface, providing configuration for accuracy, timeout, and caching behavior when requesting geographic positions.
Options:
- enableHighAccuracy - Request GPS-level accuracy (may use more power)
- timeout - Maximum time to wait for a position response
- maximumAge - Accept cached positions up to this age
Usage:
// Request high accuracy with 10-second timeout
GeolocationOptions options = new GeolocationOptions()
.setEnableHighAccuracy(true)
.setTimeout(10000)
.setMaximumAge(0); // Don't use cached positions
GeolocationApi.getCurrentPosition(myElement, options);
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns whether high accuracy is enabled.Returns the maximum age value.Returns the timeout value.static GeolocationOptionsCreates a GeolocationOptions configured for high accuracy positioning.voidinitFromJson(JsonValue json) Initializes this object's state from a parsed JSON value.static GeolocationOptionsquick()Creates a GeolocationOptions configured for quick, low-accuracy positioning.setEnableHighAccuracy(boolean enableHighAccuracy) Sets whether to request high accuracy positioning.setMaximumAge(long maximumAge) Sets the maximum age of a cached position that is acceptable.setTimeout(long timeout) Sets the maximum time to wait for a position response.Converts these options to a JavaScript options string.Serializes this object to aJsonValue.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.oorian.json.Jsonable
initFromJson, initFromJson, toJsonString
-
Constructor Details
-
GeolocationOptions
public GeolocationOptions()Constructs a GeolocationOptions with default settings.Default browser behavior is:
- enableHighAccuracy: false
- timeout: Infinity (no timeout)
- maximumAge: 0 (always get fresh position)
-
-
Method Details
-
setEnableHighAccuracy
Sets whether to request high accuracy positioning.When enabled, the device may use GPS or other high-accuracy methods, which may consume more power and take longer to acquire a position. When disabled, the device may use faster but less accurate methods like WiFi or cell tower positioning.
- Parameters:
enableHighAccuracy- True to request high accuracy, false for default accuracy.- Returns:
- This options object for method chaining.
-
setTimeout
Sets the maximum time to wait for a position response.If the position cannot be determined within this time, a timeout error will occur. Set to 0 for no timeout (wait indefinitely).
- Parameters:
timeout- The timeout in milliseconds.- Returns:
- This options object for method chaining.
-
setMaximumAge
Sets the maximum age of a cached position that is acceptable.If a cached position exists that is no older than this value, it may be returned immediately without querying the device's positioning system. Set to 0 to always request a fresh position.
- Parameters:
maximumAge- The maximum acceptable age in milliseconds.- Returns:
- This options object for method chaining.
-
getEnableHighAccuracy
Returns whether high accuracy is enabled.- Returns:
- True if high accuracy is enabled, null if not set.
-
getTimeout
Returns the timeout value.- Returns:
- The timeout in milliseconds, null if not set.
-
getMaximumAge
Returns the maximum age value.- Returns:
- The maximum age in milliseconds, null if not set.
-
highAccuracy
Creates a GeolocationOptions configured for high accuracy positioning.- Returns:
- A new GeolocationOptions with high accuracy enabled.
-
quick
Creates a GeolocationOptions configured for quick, low-accuracy positioning.Uses cached positions up to 5 minutes old and has a 5-second timeout.
- Returns:
- A new GeolocationOptions optimized for speed.
-
initFromJson
Description copied from interface:JsonableInitializes this object's state from a parsed JSON value.- Specified by:
initFromJsonin interfaceJsonable- Parameters:
json- the parsed JSON value.
-
toJsonValue
Description copied from interface:JsonableSerializes this object to aJsonValue.- Specified by:
toJsonValuein interfaceJsonable- Returns:
- the JSON representation of this object.
-
toJavaScript
Converts these options to a JavaScript options string.- Returns:
- A JavaScript object literal string representing these options.
-