Class GeolocationOptions

java.lang.Object
com.oorian.html.js.geolocation.GeolocationOptions
All Implemented Interfaces:
Jsonable

public class GeolocationOptions extends Object implements Jsonable
Configuration options for geolocation position requests.

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 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

      public GeolocationOptions setEnableHighAccuracy(boolean enableHighAccuracy)
      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

      public GeolocationOptions setTimeout(long timeout)
      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

      public GeolocationOptions setMaximumAge(long maximumAge)
      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

      public Boolean getEnableHighAccuracy()
      Returns whether high accuracy is enabled.
      Returns:
      True if high accuracy is enabled, null if not set.
    • getTimeout

      public Long getTimeout()
      Returns the timeout value.
      Returns:
      The timeout in milliseconds, null if not set.
    • getMaximumAge

      public Long getMaximumAge()
      Returns the maximum age value.
      Returns:
      The maximum age in milliseconds, null if not set.
    • highAccuracy

      public static GeolocationOptions highAccuracy()
      Creates a GeolocationOptions configured for high accuracy positioning.
      Returns:
      A new GeolocationOptions with high accuracy enabled.
    • quick

      public static GeolocationOptions 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

      public void initFromJson(JsonValue json)
      Description copied from interface: Jsonable
      Initializes this object's state from a parsed JSON value.
      Specified by:
      initFromJson in interface Jsonable
      Parameters:
      json - the parsed JSON value.
    • toJsonValue

      public JsonValue toJsonValue()
      Description copied from interface: Jsonable
      Serializes this object to a JsonValue.
      Specified by:
      toJsonValue in interface Jsonable
      Returns:
      the JSON representation of this object.
    • toJavaScript

      public String toJavaScript()
      Converts these options to a JavaScript options string.
      Returns:
      A JavaScript object literal string representing these options.