Class GeolocationErrorEvent


public class GeolocationErrorEvent extends ClientEvent<GeolocationListener>
Event fired when a geolocation error occurs.

This event is dispatched when the browser's Geolocation API cannot acquire a position. Error codes match the W3C Geolocation API specification:

  • PERMISSION_DENIED (1) - User denied permission for location access
  • POSITION_UNAVAILABLE (2) - Position could not be determined
  • TIMEOUT (3) - Position request timed out

Usage:


 public void onEvent(GeolocationErrorEvent event) {
     switch (event.getCode()) {
         case GeolocationErrorEvent.PERMISSION_DENIED:
             showError("Please enable location access in your browser settings");
             break;
         case GeolocationErrorEvent.POSITION_UNAVAILABLE:
             showError("Unable to determine your location");
             break;
         case GeolocationErrorEvent.TIMEOUT:
             showError("Location request timed out. Please try again.");
             break;
         default:
             showError("Location error: " + event.getMessage());
     }
 }
 
Author:
Marvin P. Warble Jr.
See Also:
  • Field Details

    • PERMISSION_DENIED

      public static final int PERMISSION_DENIED
      Error code: User denied the request for Geolocation.
      See Also:
    • POSITION_UNAVAILABLE

      public static final int POSITION_UNAVAILABLE
      Error code: Location information is unavailable.
      See Also:
    • TIMEOUT

      public static final int TIMEOUT
      Error code: The request to get user location timed out.
      See Also:
  • Constructor Details

    • GeolocationErrorEvent

      public GeolocationErrorEvent(int code, String message)
      Constructs a GeolocationErrorEvent with error details.
      Parameters:
      code - The error code (PERMISSION_DENIED, POSITION_UNAVAILABLE, or TIMEOUT).
      message - A human-readable error message.
    • GeolocationErrorEvent

      public GeolocationErrorEvent(int code, String message, String watchId)
      Constructs a GeolocationErrorEvent with error details and watch ID.
      Parameters:
      code - The error code.
      message - A human-readable error message.
      watchId - The watch ID if this is from a watchPosition call, null otherwise.
  • Method Details

    • getCode

      public int getCode()
      Returns the error code.
      Returns:
      One of PERMISSION_DENIED, POSITION_UNAVAILABLE, or TIMEOUT.
    • getMessage

      public String getMessage()
      Returns the error message.
      Returns:
      A human-readable description of the error.
    • getWatchId

      public String getWatchId()
      Returns the watch ID if this error is from a watchPosition call.
      Returns:
      The watch ID, or null if this is from a getCurrentPosition call.
    • isPermissionDenied

      public boolean isPermissionDenied()
      Checks if this is a permission denied error.
      Returns:
      true if the user denied location access.
    • isPositionUnavailable

      public boolean isPositionUnavailable()
      Checks if this is a position unavailable error.
      Returns:
      true if the position could not be determined.
    • isTimeout

      public boolean isTimeout()
      Checks if this is a timeout error.
      Returns:
      true if the request timed out.
    • isWatchError

      public boolean isWatchError()
      Checks if this error is from a watchPosition call.
      Returns:
      true if this is a watch error, false if from getCurrentPosition.
    • getCodeDescription

      public String getCodeDescription()
      Returns a description of the error code.
      Returns:
      A string describing the error type.
    • dispatchTo

      public void dispatchTo(GeolocationListener listener)
      Description copied from class: Event
      Dispatches this event to the specified listener.

      Subclasses implement this method to call the appropriate handler method on the listener interface.

      Specified by:
      dispatchTo in class Event<GeolocationListener>
      Parameters:
      listener - the listener to dispatch this event to
    • toString

      public String toString()
      Overrides:
      toString in class Object