Class GeolocationCoordinates

java.lang.Object
com.oorian.html.js.geolocation.GeolocationCoordinates

public class GeolocationCoordinates extends Object
Represents geographic coordinates from the Geolocation API.

This class mirrors the browser's GeolocationCoordinates interface, providing access to latitude, longitude, altitude, accuracy, and movement data obtained from the device's positioning system.

Coordinate Properties:

  • latitude/longitude - Always available, in decimal degrees
  • accuracy - Always available, in meters
  • altitude - May be null if not available
  • altitudeAccuracy - May be null if altitude is not available
  • heading - May be null if device is stationary or unable to determine
  • speed - May be null if device is stationary

Usage:


 public void onEvent(GeolocationEvent event) {
     GeolocationCoordinates coords = event.getPosition().getCoords();
     double lat = coords.getLatitude();
     double lng = coords.getLongitude();
     double accuracy = coords.getAccuracy();

     if (coords.getAltitude() != null) {
         double altitude = coords.getAltitude();
     }
 }
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • GeolocationCoordinates

      public GeolocationCoordinates(double latitude, double longitude, double accuracy, Double altitude, Double altitudeAccuracy, Double heading, Double speed)
      Constructs a GeolocationCoordinates object with all coordinate properties.
      Parameters:
      latitude - The latitude in decimal degrees.
      longitude - The longitude in decimal degrees.
      accuracy - The accuracy of the position in meters.
      altitude - The altitude in meters above the WGS84 ellipsoid, or null if unavailable.
      altitudeAccuracy - The accuracy of the altitude in meters, or null if unavailable.
      heading - The direction of travel in degrees (0-360), or null if unavailable.
      speed - The speed in meters per second, or null if unavailable.
  • Method Details

    • getLatitude

      public double getLatitude()
      Returns the latitude in decimal degrees.

      Positive values indicate north of the equator, negative values indicate south.

      Returns:
      The latitude coordinate.
    • getLongitude

      public double getLongitude()
      Returns the longitude in decimal degrees.

      Positive values indicate east of the prime meridian, negative values indicate west.

      Returns:
      The longitude coordinate.
    • getAccuracy

      public double getAccuracy()
      Returns the accuracy of the latitude and longitude in meters.

      This value represents the radius of a circle around the given position that has a 95% probability of containing the actual position.

      Returns:
      The accuracy in meters.
    • getAltitude

      public Double getAltitude()
      Returns the altitude in meters above the WGS84 ellipsoid.

      This value may be null if the device cannot determine altitude.

      Returns:
      The altitude in meters, or null if unavailable.
    • getAltitudeAccuracy

      public Double getAltitudeAccuracy()
      Returns the accuracy of the altitude in meters.

      This value may be null if altitude is not available.

      Returns:
      The altitude accuracy in meters, or null if unavailable.
    • getHeading

      public Double getHeading()
      Returns the direction of travel in degrees clockwise from true north.

      Values range from 0 to 360 degrees. This value may be null if the device is stationary or cannot determine heading.

      Returns:
      The heading in degrees, or null if unavailable.
    • getSpeed

      public Double getSpeed()
      Returns the speed in meters per second.

      This value may be null if the device is stationary or cannot determine speed.

      Returns:
      The speed in meters per second, or null if unavailable.
    • hasAltitude

      public boolean hasAltitude()
      Checks if altitude data is available.
      Returns:
      true if altitude is available, false otherwise.
    • hasHeading

      public boolean hasHeading()
      Checks if heading data is available.
      Returns:
      true if heading is available, false otherwise.
    • hasSpeed

      public boolean hasSpeed()
      Checks if speed data is available.
      Returns:
      true if speed is available, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object