Package com.oorian.html.js.geolocation
Class GeolocationErrorEvent
java.lang.Object
com.oorian.messaging.events.Event<GeolocationListener>
com.oorian.messaging.events.client.ClientEvent<GeolocationListener>
com.oorian.html.js.geolocation.GeolocationErrorEvent
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intError code: User denied the request for Geolocation.static final intError code: Location information is unavailable.static final intError code: The request to get user location timed out. -
Constructor Summary
ConstructorsConstructorDescriptionGeolocationErrorEvent(int code, String message) Constructs a GeolocationErrorEvent with error details.GeolocationErrorEvent(int code, String message, String watchId) Constructs a GeolocationErrorEvent with error details and watch ID. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatchTo(GeolocationListener listener) Dispatches this event to the specified listener.intgetCode()Returns the error code.Returns a description of the error code.Returns the error message.Returns the watch ID if this error is from a watchPosition call.booleanChecks if this is a permission denied error.booleanChecks if this is a position unavailable error.booleanChecks if this is a timeout error.booleanChecks if this error is from a watchPosition call.toString()Methods inherited from class com.oorian.messaging.events.client.ClientEvent
getSource, getTarget, setSource, setTarget
-
Field Details
-
PERMISSION_DENIED
public static final int PERMISSION_DENIEDError code: User denied the request for Geolocation.- See Also:
-
POSITION_UNAVAILABLE
public static final int POSITION_UNAVAILABLEError code: Location information is unavailable.- See Also:
-
TIMEOUT
public static final int TIMEOUTError code: The request to get user location timed out.- See Also:
-
-
Constructor Details
-
GeolocationErrorEvent
Constructs a GeolocationErrorEvent with error details.- Parameters:
code- The error code (PERMISSION_DENIED, POSITION_UNAVAILABLE, or TIMEOUT).message- A human-readable error message.
-
GeolocationErrorEvent
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
Returns the error message.- Returns:
- A human-readable description of the error.
-
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:
trueif the user denied location access.
-
isTimeout
public boolean isTimeout()Checks if this is a timeout error.- Returns:
trueif the request timed out.
-
isWatchError
public boolean isWatchError()Checks if this error is from a watchPosition call.- Returns:
trueif this is a watch error,falseif from getCurrentPosition.
-
getCodeDescription
Returns a description of the error code.- Returns:
- A string describing the error type.
-
dispatchTo
Description copied from class:EventDispatches this event to the specified listener.Subclasses implement this method to call the appropriate handler method on the listener interface.
- Specified by:
dispatchToin classEvent<GeolocationListener>- Parameters:
listener- the listener to dispatch this event to
-
toString
-