# XRGeospatialManager

Controls the lifecycle and configuration for a Geospatial Tracker.

There is only one active tracker. Adding multiple [XRGeospatialManager](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#classGoogle_1_1XR_1_1Extensions_1_1XRGeospatialManager) components is not allowed.

You may enable or disable the [XRGeospatialManager](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#classGoogle_1_1XR_1_1Extensions_1_1XRGeospatialManager) component to start or stop the tracker, the underlying resources will be released on stopped.

## Summary

### Inheritance

Inherits from: `MonoBehaviour`

| ### Public static attributes ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#initializationresult => _initializationResult` | `OpenXRResultStatus` The result returned from initialization. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#onstatechanged` | `Action< https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialStateChangedEventArgs#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialStateChangedEventArgs >` The event fired whenever the [State](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#state) changes. |

| ### Properties ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#maxnumberofsurfaceanchors = 0` | `uint` Gets the maximum number of surface anchors supported by the system. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#planetrackinginuse` | `bool` Gets a value indicating whether plane tracking is currently in use for surface anchors. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#requestedplanetracking` | `bool` Gets or sets a value indicating whether to request to use plane tracking for anchors if available. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#state` | `static https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialstate` Gets the state that represents the geospatial services. |

| ### Public attributes ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#running => _state == XRGeospatialState.Running` | `bool` Gets a value indicating whether the Geospatial tracker is running. |

| ### Public functions ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#tryattachgeospatialanchor(https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPose#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialPose geospatialPose)` | `Result< https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor >` Attempts to create a shareable anchor "attached" to the given geospatial pose. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#tryattachsurfaceanchorasync(https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialsurfacetype type, https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPose#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialPose geospatialPose, System.Threading.CancellationToken cancellationToken)` | `Awaitable< Result< https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor > >` Attempts to create a shareable anchor "attached" to the given geospatial pose relative to the location's surface. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#trycheckvpsavailabilityasync(double latitude, double longitude)` | `async Awaitable< Result< https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrvpsavailability > >` Try to check the availability of VPS near a given location asynchronously. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#trylocate(Pose pose, out https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPoseResult#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialPoseResult result)` | `bool` Try to locate the geospatial pose for the given reference frame, expressed as a pose related to Unity world space. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#trylocate(https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPose#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialPose geospatialPose, out https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRPoseResult#structGoogle_1_1XR_1_1Extensions_1_1XRPoseResult result)` | `bool` Try to locate the pose in Unity world space from a geospatial pose. |

## Public static attributes

### InitializationResult

```c#
OpenXRResultStatus InitializationResult => _initializationResult
```
The result returned from initialization.

Check OpenXRResultStatus.nativeStatusCode for the failure reason. It can be XrResult.PermissionInsufficient, [XrResultAndroid.GeospatialCloudAuthFailed](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrresultandroid_geospatialcloudauthfailed) or common OpenXR errors from XrResult. Once it's resolved, you may disable and re-enable the manager to retry initialization.

### OnStateChanged

```c#
Action< XRGeospatialStateChangedEventArgs > OnStateChanged
```
The event fired whenever the [State](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#state) changes.

## Properties

### MaxNumberOfSurfaceAnchors

```c#
uint MaxNumberOfSurfaceAnchors = 0
```
Gets the maximum number of surface anchors supported by the system.

### PlaneTrackingInUse

```c#
bool PlaneTrackingInUse
```
Gets a value indicating whether plane tracking is currently in use for surface anchors.

### RequestedPlaneTracking

```c#
bool RequestedPlaneTracking
```
Gets or sets a value indicating whether to request to use plane tracking for anchors if available.

Must be called before enabling [XRGeospatialManager](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XRGeospatialManager#classGoogle_1_1XR_1_1Extensions_1_1XRGeospatialManager).

### State

```c#
static XRGeospatialState State
```
Gets the state that represents the geospatial services.

Used to determine the status of geospatial capability and tracker state.

## Public attributes

### Running

```c#
bool Running => _state == XRGeospatialState.Running
```
Gets a value indicating whether the Geospatial tracker is running.


- Returns `true` after OnEnable() has been called and the initialization succeeded.
- Returns `false` after OnDisable() is called or the initialization failed. Accessing geospatial API under this state may result in [XrResultAndroid.GeospatialTrackerNotRunning](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrresultandroid_geospatialtrackernotrunning) error, check individual API for its requirement.

<br />

## Public functions

### TryAttachGeospatialAnchor

```c#
Result< ARShareableAnchor > TryAttachGeospatialAnchor(
  XRGeospatialPose geospatialPose
)
```
Attempts to create a shareable anchor "attached" to the given geospatial pose.


Details Parameters `geospatialPose` The geospatial pose of the target location. **Returns** The result of the operation, containing the newly added shareable anchor if the operation succeeded.

### TryAttachSurfaceAnchorAsync

```c#
Awaitable< Result< ARShareableAnchor > > TryAttachSurfaceAnchorAsync(
  XRGeospatialSurfaceType type,
  XRGeospatialPose geospatialPose,
  System.Threading.CancellationToken cancellationToken
)
```
Attempts to create a shareable anchor "attached" to the given geospatial pose relative to the location's surface.


Details Parameters `type` The surface type of the geospatial anchor. `geospatialPose` The geospatial pose of the target location where [XRGeospatialPose.Altitude](https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPose#altitude) represents the altitude in meters relative to the surface. `cancellationToken` An optional CancellationToken. Exceptions `OperationCanceledException` Thrown if the operation has been canceled either by the caller or the Unity main thread. **Returns** The result of the operation, containing the newly added shareable anchor if the operation succeeded.

### TryCheckVPSAvailabilityAsync

```c#
async Awaitable< Result< XRVPSAvailability > > TryCheckVPSAvailabilityAsync(
  double latitude,
  double longitude
)
```
Try to check the availability of VPS near a given location asynchronously.

A [XRGeospatialState.Running](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialstate_running) tracker is not required, as long as Geospatial is supported and enabled by the current session.


Details Parameters `latitude` The latitude of the location. `longitude` The longitude of the location. **Returns** The result of the asynchronous operation. It can fail with XrResult.PermissionInsufficient, [XrResultAndroid.GeospatialCoordinateInvalid](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrresultandroid_geospatialcoordinateinvalid), and other common OpenXR errors from XrResult.

### TryLocate

```c#
bool TryLocate(
  Pose pose,
  out XRGeospatialPoseResult result
)
```
Try to locate the geospatial pose for the given reference frame, expressed as a pose related to Unity world space.

A [XRGeospatialState.Running](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialstate_running) tracker is required.


Details Parameters `pose` The pose in Unity world space to be converted. `result` The result of geospatial pose. **Returns** True if the calculation succeeded, and use [XRGeospatialPoseResult.LocationFlags](https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPoseResult#locationflags) to determine which fields are valid.

### TryLocate

```c#
bool TryLocate(
  XRGeospatialPose geospatialPose,
  out XRPoseResult result
)
```
Try to locate the pose in Unity world space from a geospatial pose.

A [XRGeospatialState.Running](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialstate_running) tracker is required.


Details Parameters `geospatialPose` The geospatial pose to be converted. `result` The result of the pose in Unity world space. **Returns** True if the calculation succeeded, and use [XRPoseResult.LocationFlags](https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRPoseResult#locationflags) to determine which fields are valid. Otherwise, returns `false`. You may retry later with a different geospatial pose.