Package com.oorian.html.js.geolocation
Class GeolocationPosition
java.lang.Object
com.oorian.html.js.geolocation.GeolocationPosition
Represents a geographic position from the Geolocation API.
This class mirrors the browser's GeolocationPosition interface, containing the coordinates and the timestamp when the position was acquired.
Usage:
public void onEvent(GeolocationEvent event) {
GeolocationPosition position = event.getPosition();
GeolocationCoordinates coords = position.getCoords();
long timestamp = position.getTimestamp();
System.out.println("Position acquired at: " + new Date(timestamp));
System.out.println("Latitude: " + coords.getLatitude());
System.out.println("Longitude: " + coords.getLongitude());
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGeolocationPosition(GeolocationCoordinates coords, long timestamp) Constructs a GeolocationPosition with coordinates and timestamp. -
Method Summary
Modifier and TypeMethodDescriptiondoubleConvenience method to get the accuracy from the coordinates.Returns the geographic coordinates of this position.doubleConvenience method to get the latitude from the coordinates.doubleConvenience method to get the longitude from the coordinates.longReturns the timestamp when this position was acquired.toString()
-
Constructor Details
-
GeolocationPosition
Constructs a GeolocationPosition with coordinates and timestamp.- Parameters:
coords- The geographic coordinates.timestamp- The time at which the position was acquired, in milliseconds since epoch.
-
-
Method Details
-
getCoords
Returns the geographic coordinates of this position.- Returns:
- The coordinates containing latitude, longitude, and optional altitude/movement data.
-
getTimestamp
public long getTimestamp()Returns the timestamp when this position was acquired.The timestamp is in milliseconds since the Unix epoch (January 1, 1970 00:00:00 UTC).
- Returns:
- The timestamp in milliseconds.
-
getLatitude
public double getLatitude()Convenience method to get the latitude from the coordinates.- Returns:
- The latitude in decimal degrees.
-
getLongitude
public double getLongitude()Convenience method to get the longitude from the coordinates.- Returns:
- The longitude in decimal degrees.
-
getAccuracy
public double getAccuracy()Convenience method to get the accuracy from the coordinates.- Returns:
- The accuracy in meters.
-
toString
-