Package com.oorian.html.js.geolocation
Class GeolocationEvent
java.lang.Object
com.oorian.messaging.events.Event<GeolocationListener>
com.oorian.messaging.events.client.ClientEvent<GeolocationListener>
com.oorian.html.js.geolocation.GeolocationEvent
Event fired when a geographic position is successfully acquired.
This event is dispatched to elements that have requested geolocation data via
GeolocationApi.getCurrentPosition(com.oorian.html.Element) or GeolocationApi.watchPosition(com.oorian.html.Element).
The event contains the position data including coordinates and timestamp.
Usage:
public void onEvent(GeolocationEvent event) {
GeolocationPosition position = event.getPosition();
double lat = position.getLatitude();
double lng = position.getLongitude();
double accuracy = position.getAccuracy();
// Check if this is a watch update
if (event.getWatchId() != null) {
// Continuous tracking update
updateLocationMarker(lat, lng);
} else {
// One-time position request
showLocation(lat, lng, accuracy);
}
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGeolocationEvent(GeolocationPosition position) Constructs a GeolocationEvent with position data.GeolocationEvent(GeolocationPosition position, String watchId) Constructs a GeolocationEvent with position data and watch ID. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatchTo(GeolocationListener listener) Dispatches this event to the specified listener.doubleConvenience method to get the accuracy.Convenience method to get the coordinates.doubleConvenience method to get the latitude.doubleConvenience method to get the longitude.Returns the geographic position.Returns the watch ID if this event is from a watchPosition call.booleanChecks if this event is from a watchPosition call.Methods inherited from class com.oorian.messaging.events.client.ClientEvent
getSource, getTarget, setSource, setTarget
-
Constructor Details
-
GeolocationEvent
Constructs a GeolocationEvent with position data.- Parameters:
position- The geographic position that was acquired.
-
GeolocationEvent
Constructs a GeolocationEvent with position data and watch ID.- Parameters:
position- The geographic position that was acquired.watchId- The watch ID if this is from a watchPosition call, null otherwise.
-
-
Method Details
-
getPosition
Returns the geographic position.- Returns:
- The position containing coordinates and timestamp.
-
getWatchId
Returns the watch ID if this event is from a watchPosition call.- Returns:
- The watch ID, or null if this is from a getCurrentPosition call.
-
getLatitude
public double getLatitude()Convenience method to get the latitude.- Returns:
- The latitude in decimal degrees.
-
getLongitude
public double getLongitude()Convenience method to get the longitude.- Returns:
- The longitude in decimal degrees.
-
getAccuracy
public double getAccuracy()Convenience method to get the accuracy.- Returns:
- The accuracy in meters.
-
getCoords
Convenience method to get the coordinates.- Returns:
- The geographic coordinates.
-
isWatchUpdate
public boolean isWatchUpdate()Checks if this event is from a watchPosition call.- Returns:
trueif this is a watch update,falseif from getCurrentPosition.
-
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
-