Class GeolocationEvent


public class GeolocationEvent extends ClientEvent<GeolocationListener>
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 Details

    • GeolocationEvent

      public GeolocationEvent(GeolocationPosition position)
      Constructs a GeolocationEvent with position data.
      Parameters:
      position - The geographic position that was acquired.
    • GeolocationEvent

      public GeolocationEvent(GeolocationPosition position, String watchId)
      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

      public GeolocationPosition getPosition()
      Returns the geographic position.
      Returns:
      The position containing coordinates and timestamp.
    • getWatchId

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

      public GeolocationCoordinates 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:
      true if this is a watch update, false if from getCurrentPosition.
    • 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