Geospatial


public final class Geospatial


Provides localization ability in Earth-relative coordinates.

To use the Geospatial object, configure the session with androidx.xr.runtime.GeospatialMode.VPS_AND_GPS.

Not all devices support androidx.xr.runtime.GeospatialMode.VPS_AND_GPS, use ConfigMode.isSupported to check if the current device supports enabling this mode.

The Geospatial object should only be used when its State is State.Running, and otherwise should not be used. Use Geospatial.state to obtain the current State.

Summary

Nested types

public final class Geospatial.State

Describes the state of Geospatial.

public final class Geospatial.Surface

The type of surface on which to create an anchor.

Public methods

final @NonNull VpsAvailabilityResult
checkVpsAvailability(double latitude, double longitude)

Gets the availability of the Visual Positioning System (VPS) at a specified horizontal position.

final @NonNull AnchorCreateResult
createAnchor(
    double latitude,
    double longitude,
    double altitude,
    @NonNull Quaternion eastUpSouthQuaternion
)

Creates a new Anchor at the specified geospatial location and orientation relative to the Earth.

final @NonNull AnchorCreateResult
createAnchorOnSurface(
    double latitude,
    double longitude,
    double altitudeAboveSurface,
    @NonNull Quaternion eastUpSouthQuaternion,
    @NonNull Geospatial.Surface surface
)

Asynchronously creates a new Anchor at a specified horizontal position and altitude relative to the horizontal position's surface (Terrain or Rooftop).

final @NonNull CreateGeospatialPoseFromPoseResult

Converts the input Pose to a GeospatialPose in the same position as the original pose.

final @NonNull CreatePoseFromGeospatialPoseResult

Converts the input geospatial location and orientation relative to the Earth to a Pose in the same position.

boolean
equals(Object other)
static final @NonNull Geospatial

Returns the Geospatial object for the given Session.

final @NonNull StateFlow<@NonNull Geospatial.State>

The current State of Geospatial.

int

Extension functions

final @NonNull ListenableFuture<@NonNull VpsAvailabilityResult>
GuavaGeospatial.checkVpsAvailabilityAsync(
    @NonNull Geospatial receiver,
    @NonNull Session session,
    double latitude,
    double longitude
)

Gets the availability of the Visual Positioning System (VPS) at a specified horizontal position.

final @NonNull Flowable<@NonNull Geospatial.State>

The current State of Geospatial.

Public methods

checkVpsAvailability

public final @NonNull VpsAvailabilityResult checkVpsAvailability(double latitude, double longitude)

Gets the availability of the Visual Positioning System (VPS) at a specified horizontal position. The availability of VPS in a given location helps to improve the quality of Geospatial localization and tracking accuracy.

This launches an asynchronous operation used to query the Google Cloud ARCore API. It may be called without calling Session.configure.

Your app must be properly set up to communicate with the Google Cloud ARCore API in order to obtain a result from this call, otherwise the result will be VpsAvailabilityNotAuthorized.

Parameters
double latitude

The latitude in degrees.

double longitude

The longitude in degrees.

Returns
@NonNull VpsAvailabilityResult

the result of the VPS availability check.

createAnchor

Added in 1.0.0-alpha11
public final @NonNull AnchorCreateResult createAnchor(
    double latitude,
    double longitude,
    double altitude,
    @NonNull Quaternion eastUpSouthQuaternion
)

Creates a new Anchor at the specified geospatial location and orientation relative to the Earth.

Latitude and longitude are defined by the WGS84 specification, and the altitude value is defined by the elevation above the WGS84 ellipsoid in meters. To create an anchor using an altitude relative to the Earth's terrain instead of altitude above the WGS84 ellipsoid, use Geospatial.createAnchorOnTerrain.

The rotation quaternion provided is with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.

The tracking state of an Anchor will permanently become TrackingState.Stopped if the androidx.xr.runtime.GeospatialMode is disabled, or if another full-space app uses Geospatial.

Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1 degrees of the north pole or south pole (90 degrees or -90 degrees), this function will throw IllegalArgumentException.

Parameters
double latitude

the latitude of the anchor.

double longitude

the longitude of the anchor.

double altitude

the altitude of the anchor.

@NonNull Quaternion eastUpSouthQuaternion

the rotation quaternion of the anchor.

Throws
IllegalArgumentException

if the latitude is outside the allowable range.

createAnchorOnSurface

public final @NonNull AnchorCreateResult createAnchorOnSurface(
    double latitude,
    double longitude,
    double altitudeAboveSurface,
    @NonNull Quaternion eastUpSouthQuaternion,
    @NonNull Geospatial.Surface surface
)

Asynchronously creates a new Anchor at a specified horizontal position and altitude relative to the horizontal position's surface (Terrain or Rooftop).

The specified altitudeAboveSurface is interpreted to be relative to the given surface at the specified latitude/longitude geospatial coordinates, rather than relative to the WGS84 ellipsoid. Specifying an altitude of 0 will position the anchor directly on the surface whereas specifying a positive altitude will position the anchor above the surface, against the direction of gravity.

Surface.TERRAIN refers to the Earth's terrain (or floor) and Surface.ROOFTOP refers to the top of a building at the given horizontal location. If there is no building at the given location, then the rooftop surface is interpreted to be the terrain instead.

You may resolve multiple anchors at a time, but a session cannot be tracking more than 100 surface anchors at time. Attempting to resolve more than 100 surface anchors will return an AnchorCreateResourcesExhausted result.

Creating a Terrain anchor requires an active Earth which is EarthState.Running. If it is not, then this function returns an AnchorCreateIllegalState result. This call also requires a working internet connection to communicate with the ARCore API on Google Cloud. ARCore will continue to retry if it is unable to establish a connection to the ARCore service.

A Terrain anchor's tracking state will be TrackingState.Paused if the Earth is not actively tracking. Its tracking state will permanently become TrackingState.Stopped if androidx.xr.runtime.GeospatialMode is disabled, or if another full-space app uses Geospatial.

Latitude and longitude are defined by the WGS84 specification, and the altitude value is defined by the elevation above the Earth's terrain (or floor) in meters.

The rotation quaternion provided is with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.

Parameters
double latitude

the latitude of the anchor.

double longitude

the longitude of the anchor.

double altitudeAboveSurface

The altitude of the anchor above the given surface.

@NonNull Quaternion eastUpSouthQuaternion

the rotation quaternion of the anchor.

@NonNull Geospatial.Surface surface

the surface on which to create the anchor.

Throws
IllegalArgumentException

if the latitude is outside the allowable range.

createGeospatialPoseFromPose

Added in 1.0.0-alpha11
public final @NonNull CreateGeospatialPoseFromPoseResult createGeospatialPoseFromPose(@NonNull Pose pose)

Converts the input Pose to a GeospatialPose in the same position as the original pose.

This method may return a GeospatialPoseNotTracking result if Geospatial is not currently tracking.

Parameters
@NonNull Pose pose

the Pose to be converted into a GeospatialPose.

createPoseFromGeospatialPose

Added in 1.0.0-alpha11
public final @NonNull CreatePoseFromGeospatialPoseResult createPoseFromGeospatialPose(@NonNull GeospatialPose geospatialPose)

Converts the input geospatial location and orientation relative to the Earth to a Pose in the same position.

This method may return a PoseNotTracking result if Geospatial is not currently tracking.

Positions near the north pole or south pole is not supported. If the latitude is within 0.1 degrees of the north pole or south pole (90 degrees or -90 degrees), this function will throw an IllegalArgumentException.

Parameters
@NonNull GeospatialPose geospatialPose

the GeospatialPose to be converted into a Pose.

Throws
IllegalArgumentException

if the latitude is within 0.1 degrees of the north pole or south pole (90 degrees or -90 degrees).

equals

public boolean equals(Object other)

getInstance

Added in 1.0.0-alpha11
public static final @NonNull Geospatial getInstance(@NonNull Session session)

Returns the Geospatial object for the given Session.

Parameters
@NonNull Session session

the Session to get the Geospatial object from.

getState

Added in 1.0.0-alpha11
public final @NonNull StateFlow<@NonNull Geospatial.StategetState()

The current State of Geospatial.

hashCode

public int hashCode()

Extension functions

GuavaGeospatial.checkVpsAvailabilityAsync

public final @NonNull ListenableFuture<@NonNull VpsAvailabilityResultGuavaGeospatial.checkVpsAvailabilityAsync(
    @NonNull Geospatial receiver,
    @NonNull Session session,
    double latitude,
    double longitude
)

Gets the availability of the Visual Positioning System (VPS) at a specified horizontal position. The availability of VPS in a given location helps to improve the quality of Geospatial localization and tracking accuracy.

This launches an asynchronous operation used to query the Google Cloud ARCore API. It may be called without calling Session.configure.

Your app must be properly set up to communicate with the Google Cloud ARCore API in order to obtain a result from this call, otherwise the result will be VpsAvailabilityNotAuthorized.

Parameters
@NonNull Session session

The current Session.

double latitude

The latitude in degrees.

double longitude

The longitude in degrees.

Returns
@NonNull ListenableFuture<@NonNull VpsAvailabilityResult>

the result of the VPS availability check.

RxJava3Geospatial.getStateAsFlowable

public final @NonNull Flowable<@NonNull Geospatial.StateRxJava3Geospatial.getStateAsFlowable(@NonNull Geospatial receiver)

The current State of Geospatial.