Class GeolocationCoordinates
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 Summary
ConstructorsConstructorDescriptionGeolocationCoordinates(double latitude, double longitude, double accuracy, Double altitude, Double altitudeAccuracy, Double heading, Double speed) Constructs a GeolocationCoordinates object with all coordinate properties. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the accuracy of the latitude and longitude in meters.Returns the altitude in meters above the WGS84 ellipsoid.Returns the accuracy of the altitude in meters.Returns the direction of travel in degrees clockwise from true north.doubleReturns the latitude in decimal degrees.doubleReturns the longitude in decimal degrees.getSpeed()Returns the speed in meters per second.booleanChecks if altitude data is available.booleanChecks if heading data is available.booleanhasSpeed()Checks if speed data is available.toString()
-
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
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
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
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
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:
trueif altitude is available,falseotherwise.
-
hasHeading
public boolean hasHeading()Checks if heading data is available.- Returns:
trueif heading is available,falseotherwise.
-
hasSpeed
public boolean hasSpeed()Checks if speed data is available.- Returns:
trueif speed is available,falseotherwise.
-
toString
-