> For the complete documentation index, see [llms.txt](https://docs.multiset.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/polling-api.md).

# Polling API

Everything you can read from MultiSet.shared at any time or on every frame: run and session state, the map and geo alignment, conversions between the AR session, the map and Earth, and the device's li

## Overview

The SDK tells you about events through [`MultiSetCallback`](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetcallback.md). It also keeps its current state, which you can read whenever you need it. This page lists every call of that second kind.

| You need                                                                                     | Use                                                                                                          |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| A value that is current on every frame, such as where to draw content or where the device is | Polling, on this page                                                                                        |
| A moment, such as a fix arriving, a failure or the alignment changing                        | [`MultiSetCallback`](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetcallback.md) |

Every call on this page is synchronous, makes no network request and is cheap enough to make on every frame. Call them on the main thread, like the rest of `MultiSet.shared`.

{% hint style="info" %}
The alignment, conversion and device position calls on this page are available from **iOS SDK 2.4.0** and above.
{% endhint %}

***

## At a Glance

| Call                                                                                         | Returns                                                    |
| -------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| `MultiSet.shared.mapAlignment`                                                               | Where the map sits in the AR session                       |
| `MultiSet.shared.geoAlignment`                                                               | Where the AR session sits on Earth                         |
| `MultiSet.shared.mapAlignmentAvailability`                                                   | Whether `mapAlignment` can be used, and why not            |
| `MultiSet.shared.geoAlignmentAvailability`                                                   | Whether `geoAlignment` can be used, and why not            |
| `MultiSet.shared.deviceGeolocation(headingMode:)`                                            | The device's latitude, longitude, altitude and heading now |
| `MultiSet.shared.deviceMapPose()`                                                            | The device's pose in the map now                           |
| `MultiSet.shared.localizationStage`, `objectTrackingStage`                                   | The stage of the current run                               |
| `MultiSet.shared.recoveryPhase`, `needsRealignment`                                          | Recovery after a tracking break                            |
| `MultiSet.shared.isLocalizing`, `hasLocalized`, `anchorTrust` and the other state properties | Run and session state                                      |

***

## Run and Session State

| Property                                  | Type                | Description                                                                                                          |
| ----------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `isLocalizing`                            | `Bool`              | A localization run is in progress or a silent retry is due                                                           |
| `isShowingOverlay`                        | `Bool`              | A run the user is waiting on is in progress: cover the scene                                                         |
| `isCapturingFrames`                       | `Bool`              | Frames are being captured                                                                                            |
| `localizationStage`                       | `LocalizationStage` | The current localization run's stage: `.idle`, `.capturing(captured:required:)`, `.uploading` or `.awaitingResponse` |
| `hasLocalized`                            | `Bool`              | A fix has been accepted in this session                                                                              |
| `recoveryPhase`                           | `RecoveryPhase`     | Recovery after a tracking break: `.none`, `.waitingForTracking` or `.realigning`                                     |
| `needsRealignment`                        | `Bool`              | The scene is out of place after a tracking break. Hide content placed in the map frame while it is `true`            |
| `anchorTrust`                             | `AnchorTrust`       | Standing of the pose consistency anchor: `.provisional`, `.corroborated` or `.trusted`                               |
| `isObjectTrackingActive`                  | `Bool`              | An object tracking run is requested or in progress                                                                   |
| `isShowingObjectTrackingOverlay`          | `Bool`              | Like `isObjectTrackingActive`, without background re-tracking                                                        |
| `objectTrackingStage`                     | `LocalizationStage` | The current object tracking run's stage                                                                              |
| `hasTrackedObject`                        | `Bool`              | An object has been tracked in this session                                                                           |
| `isLoadingMapMesh`, `isLoadingObjectMesh` | `Bool`              | A mesh is being fetched                                                                                              |
| `isMapMeshLoading`, `isObjectMeshLoading` | `Bool`              | A mesh is being fetched or built into the AR scene (from the AR adapter)                                             |

```swift
// For example, once per frame
switch MultiSet.shared.localizationStage {
case .capturing(let captured, let required): statusLabel.text = "Capturing \(captured) of \(required)"
case .uploading: statusLabel.text = "Uploading…"
case .awaitingResponse: statusLabel.text = "Matching against the map…"
case .idle: statusLabel.text = nil
@unknown default: statusLabel.text = nil
}
```

The stage properties do not say whether a run is a background one. Read `isShowingOverlay` for that: it is `false` for background refreshes and recoveries. The callback form, `onLocalizationStageChanged(_:isBackground:)`, carries the flag. See [Showing a Run's Progress](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/lifecycle-and-runtimes.md#showing-a-runs-progress).

***

## Map and Geo Alignment

The SDK keeps the alignment from the last accepted fix. You can ask at any time where the map is in the AR session and where the session is on Earth, and convert between the three spaces without writing the maths yourself.

| Space      | Units and axes                                                                                                |
| ---------- | ------------------------------------------------------------------------------------------------------------- |
| AR session | Metres, right-handed, +Y up, gravity-aligned (ARKit)                                                          |
| Map        | Metres, right-handed, +Y up (the Map or MapSet)                                                               |
| Earth      | WGS84 latitude and longitude, metres above the WGS84 ellipsoid, headings in degrees clockwise from true north |

```swift
MultiSet.shared.mapAlignment: MapAlignment?               // map and AR session
MultiSet.shared.geoAlignment: GeoAlignment?               // Earth and AR session
MultiSet.shared.mapAlignmentAvailability: AlignmentAvailability
MultiSet.shared.geoAlignmentAvailability: AlignmentAvailability
```

Each getter returns a snapshot that never changes after you read it. Read the getter again for a newer one. Snapshots are `Sendable`, so you can hand one to another thread.

Between fixes the answers stay current, because the device keeps moving through ARKit's own tracking. Each accepted fix refines the alignment.

### Requirements for geo alignment

* `MultiSetConfig.geoCoordinatesInResponse = true`.
* A Map or MapSet that is georeferenced in the portal, with an altitude.
* An AR session that is gravity-aligned (`worldAlignment = .gravity`), which `MultiSetARView` sets. With `.gravityAndHeading`, ARKit can turn the session as the compass settles, which invalidates the alignment between fixes.

`mapAlignment` needs none of these.

***

## Availability

When a getter returns `nil`, its availability says why.

| Case                   | Applies to | Meaning                                                                                                                                                 |
| ---------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `.available`           | Both       | Conversions work                                                                                                                                        |
| `.notLocalized`        | Both       | No accepted fix in this session yet                                                                                                                     |
| `.needsRealignment`    | Both       | A tracking break put the scene out of place. Localize again                                                                                             |
| `.geoNotRequested`     | Geo        | `geoCoordinatesInResponse` is off                                                                                                                       |
| `.mapNotGeoreferenced` | Geo        | The fix carried no usable geographic position: the map is not georeferenced, or has no altitude                                                         |
| `.serverUnsupported`   | Geo        | The server did not send the map's heading. Needs MultiSet [version 2.5.1](https://docs.multiset.ai/quick-access/changelog/v2/version-2.5.1.md) or later |

`AlignmentAvailability` may gain cases in a later release, so a `switch` over it needs `@unknown default`.

```swift
switch MultiSet.shared.geoAlignmentAvailability {
case .available: break
case .notLocalized, .needsRealignment: showHint("Point the camera at the space")
case .geoNotRequested, .mapNotGeoreferenced, .serverUnsupported: hideGeoContent()
@unknown default: hideGeoContent()
}
```

### When the alignment is cleared

| Cleared by                                                                        | Kept through                               |
| --------------------------------------------------------------------------------- | ------------------------------------------ |
| A tracking break that puts the scene out of place, also with `relocalization` off | `stopLocalization()`                       |
| `resetSession()`                                                                  | `resetPoseConsistencyReference()`          |
| A different AR session being attached                                             | A brief tracking wobble                    |
| `release()`                                                                       | A failed localization attempt              |
| `updateConfig(_:)` changing the Map or MapSet                                     | A fix the pose consistency check discarded |

It becomes available again on the next accepted fix.

***

## MapAlignment

Where the map sits in the AR session.

| Member                            | Type            | Description                                                                             |
| --------------------------------- | --------------- | --------------------------------------------------------------------------------------- |
| `anchor`                          | `AnchorPose`    | Pose of the map origin in the AR session. The same pose the scene's map anchor received |
| `trust`                           | `AnchorTrust`   | Standing of that anchor                                                                 |
| `mapCodes`                        | `[String]`      | Map codes of the fix the anchor came from                                               |
| `timestamp`                       | `Date`          | Time of that fix                                                                        |
| `mapToSession`                    | `simd_float4x4` | The same pose as a matrix, from map coordinates to AR session coordinates               |
| `sessionPosition(ofMapPoint:)`    | `SIMD3<Float>`  | A map point, in the AR session                                                          |
| `mapPosition(ofSessionPoint:)`    | `SIMD3<Float>`  | An AR session point, in the map                                                         |
| `sessionPose(ofMapPose:)`         | `AnchorPose`    | A map pose, in the AR session                                                           |
| `mapPose(ofSessionPose:)`         | `AnchorPose`    | An AR session pose, in the map                                                          |
| `mapPose(ofCamera:orientation:)`  | `AnchorPose`    | A camera's pose in the map, from its raw transform and the interface orientation        |
| `replacingAnchor(_:)`             | `MapAlignment`  | The same alignment with a different anchor                                              |
| `MapAlignment.fromLeftHanded(_:)` | `AnchorPose`    | Converts a pose authored in a left-handed tool such as Unity into map coordinates       |

Content parented under `MultiSetARView.parentEntity` follows the map by itself. For anything else, convert through `MapAlignment`:

```swift
guard let map = MultiSet.shared.mapAlignment else { return }

// A point given in map coordinates, in the AR session
let sessionPoint = map.sessionPosition(ofMapPoint: [2.5, 0, -4])

// The map pose of content the user just placed
let savedPose = map.mapPose(ofSessionPose: AnchorPose(
    position: entity.position(relativeTo: nil),
    rotation: entity.orientation(relativeTo: nil)))
```

To keep content across sessions, save its map pose together with the map code (`map.mapCodes`), and place it again with `sessionPose(ofMapPose:)` after the next fix.

{% hint style="warning" %}
Poses copied from Unity must go through `MapAlignment.fromLeftHanded(_:)` first. Without it the content is mirrored.
{% endhint %}

***

## GeoAlignment

Where the AR session sits on Earth.

| Member                                           | Type              | Description                                                                    |
| ------------------------------------------------ | ----------------- | ------------------------------------------------------------------------------ |
| `map`                                            | `MapAlignment`    | The map alignment this geo alignment builds on                                 |
| `georeference`                                   | `MapGeoreference` | Where the map sits on Earth: its `origin` and `mapHeadingDegrees`              |
| `sessionOrigin`                                  | `GeoCoordinates`  | Where the AR session origin is on Earth                                        |
| `sessionHeadingDegrees`                          | `Double`          | Compass bearing of the AR session's −Z axis                                    |
| `sessionPosition(of:)`                           | `SIMD3<Float>`    | A place on Earth, in the AR session                                            |
| `sessionPose(of:facingDegrees:)`                 | `AnchorPose`      | A place on Earth, in the AR session, with its −Z axis facing a compass bearing |
| `coordinates(ofSessionPoint:)`                   | `GeoCoordinates`  | An AR session point, on Earth                                                  |
| `geolocation(ofSessionPose:)`                    | `Geolocation`     | An AR session pose, on Earth, with the compass bearing of its −Z axis          |
| `geolocation(ofCamera:orientation:headingMode:)` | `Geolocation`     | A camera on Earth, from its raw transform and the interface orientation        |
| `coordinates(ofMapPoint:)`                       | `GeoCoordinates`  | A map point, on Earth                                                          |
| `mapPosition(of:)`                               | `SIMD3<Float>`    | A place on Earth, in the map                                                   |
| `accuracy(atSessionPoint:)`                      | `GeoAccuracy`     | Estimated accuracy of a conversion at that point                               |
| `replacingAnchor(_:)`                            | `GeoAlignment`    | The same alignment with a different anchor                                     |

### Placing content at a coordinate

Pass the latitude, longitude and altitude of the content itself, and the compass direction its front (−Z axis) should face.

```swift
guard let geo = MultiSet.shared.geoAlignment else { return }

// A marker at a surveyed point, facing east
let place = GeoCoordinates(latitude: 12.952603, longitude: 77.616157, altitude: 913.4)
let pose = geo.sessionPose(of: place, facingDegrees: 90)
marker.setPosition(pose.position, relativeTo: nil)
marker.setOrientation(pose.rotation, relativeTo: nil)
```

{% hint style="warning" %}
Content placed in session space does not follow later fixes. Place it relative to the world, not under `parentEntity`, and place it again in `onAlignmentChanged(map:geo:)` (see [MultiSetCallback](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetcallback.md)). Alternatively, convert the coordinate once with `geo.mapPosition(of:)` and parent the content under `parentEntity` at that map position: it then moves with every fix.
{% endhint %}

### Complete example: content at several coordinates

This helper keeps a list of entities with the place on Earth each one belongs at. It hides them until the SDK has a geo alignment, and places them again on every change.

```swift
import RealityKit
import MultiSetSDK

@MainActor
final class GeoContentPlacer {

    private struct Item {
        let entity: Entity
        let coordinates: GeoCoordinates
        let facingDegrees: Double
    }

    private var items: [Item] = []
    private let root = AnchorEntity(world: .zero)

    init(arView: ARView) {
        arView.scene.addAnchor(root)
    }

    /// Registers content at a place on Earth. It stays hidden until the SDK has a geo alignment.
    /// - Parameter facingDegrees: Compass bearing the content's -Z axis faces. 0 is north, 90 east.
    func add(_ entity: Entity, latitude: Double, longitude: Double, ellipsoidalAltitude: Double,
             facingDegrees: Double = 0) {
        root.addChild(entity)
        items.append(Item(
            entity: entity,
            coordinates: GeoCoordinates(latitude: latitude, longitude: longitude, altitude: ellipsoidalAltitude),
            facingDegrees: facingDegrees))
        place(using: MultiSet.shared.geoAlignment)
    }

    /// Call from `MultiSetCallback.onAlignmentChanged(map:geo:)`.
    /// `geo` is nil after a tracking break or a reset.
    func place(using geo: GeoAlignment?) {
        for item in items {
            guard let geo else {
                item.entity.isEnabled = false
                continue
            }
            let pose = geo.sessionPose(of: item.coordinates, facingDegrees: item.facingDegrees)
            item.entity.setPosition(pose.position, relativeTo: nil)
            item.entity.setOrientation(pose.rotation, relativeTo: nil)
            item.entity.isEnabled = true
        }
    }
}
```

Wire it to the alignment callback, then add content:

```swift
// In your MultiSetCallback
func onAlignmentChanged(map: MapAlignment?, geo: GeoAlignment?) {
    placer.place(using: geo)
}

// Anywhere, before or after the first fix
placer.add(sign, latitude: 34.05591, longitude: -117.19661, ellipsoidalAltitude: 360.8,
           facingDegrees: 90)
```

When nothing shows, `MultiSet.shared.geoAlignmentAvailability` gives the reason.

### Driving an external scene camera

A geospatial scene that draws its own camera needs to know where the AR session origin is on Earth and which way the session faces:

```swift
guard let geo = MultiSet.shared.geoAlignment else { return }
let origin = geo.sessionOrigin              // GeoCoordinates of the session origin
let heading = geo.sessionHeadingDegrees     // compass bearing of the session's -Z axis
```

Place the external camera at `origin`, turned to `heading`, and move it by the AR camera's session transform each frame.

### Rules

* **Altitude** is metres above the WGS84 ellipsoid, in and out. CoreLocation's `altitude` is above mean sea level; use `ellipsoidalAltitude`. A `GeoCoordinates` with no altitude is placed at the altitude of the map origin.
* **Heading** is degrees clockwise from true north, from 0 up to 360. It is `nil` when the direction asked about is within 15° of straight up or down. The position is still returned.
* **Geo content is always upright.** Pitch and roll come from the AR session's gravity.

***

## Device Position

Both calls come from the AR adapter (the `MultiSetSDK` product) and read the current ARKit frame. They return `nil` without a camera frame or without the matching alignment.

| Call                                              | Returns                                                                             |
| ------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `MultiSet.shared.deviceGeolocation(headingMode:)` | `Geolocation?`: where the device is on Earth now, and which way it faces            |
| `MultiSet.shared.deviceMapPose()`                 | `AnchorPose?`: the device's pose in the map now, the "you are here" of a floor plan |

```swift
// Once per frame, on the main thread
func updateBlueDot() {
    guard let here = MultiSet.shared.deviceGeolocation() else { return }
    blueDot.move(to: here.coordinates, heading: here.headingDegrees)
}
```

| `HeadingMode`              | Heading describes                                                                    |
| -------------------------- | ------------------------------------------------------------------------------------ |
| `.cameraForward` (default) | The direction the camera looks. Right for an AR view held upright                    |
| `.deviceTop`               | The device's top edge, in any orientation. Right for a phone held flat over a 2D map |

The rotation of `deviceMapPose()` follows the same convention as `LocalizationResult.estimatedRotation`.

On a custom AR runtime, with only `MultiSetCore`, pass the raw camera transform and the interface orientation to `GeoAlignment.geolocation(ofCamera:orientation:headingMode:)` and `MapAlignment.mapPose(ofCamera:orientation:)`.

***

## Types

### Geolocation

| Property         | Type             | Description                                                |
| ---------------- | ---------------- | ---------------------------------------------------------- |
| `coordinates`    | `GeoCoordinates` | Latitude, longitude and altitude above the WGS84 ellipsoid |
| `headingDegrees` | `Double?`        | Degrees clockwise from true north, or `nil` near vertical  |
| `accuracy`       | `GeoAccuracy?`   | Estimated accuracy                                         |
| `timestamp`      | `Date`           | Time of the fix the alignment came from                    |

### GeoAccuracy

| Property           | Type     | Description                   |
| ------------------ | -------- | ----------------------------- |
| `horizontalMeters` | `Double` | Horizontal accuracy in metres |
| `verticalMeters`   | `Double` | Vertical accuracy in metres   |
| `headingDegrees`   | `Double` | Heading accuracy in degrees   |

The values are 1-sigma estimates. They grow as you move away from where the device last localized, and they do not include any error in the map's own georeference.

### MapGeoreference

| Property            | Type             | Description                                                        |
| ------------------- | ---------------- | ------------------------------------------------------------------ |
| `origin`            | `GeoCoordinates` | The map origin on Earth. Its altitude is always set                |
| `mapHeadingDegrees` | `Double`         | Azimuth of the map's +Z axis, in degrees clockwise from true north |

### AnchorPose

| Property   | Type           | Description        |
| ---------- | -------------- | ------------------ |
| `position` | `SIMD3<Float>` | Position in metres |
| `rotation` | `simd_quatf`   | Rotation           |

***

## Smoothing

By default the map anchor jumps to each new fix. To glide instead:

```swift
MultiSet.shared.setAlignmentSmoothing(.interpolate(seconds: 0.3))
```

| `AlignmentSmoothing`     | Behavior                                     |
| ------------------------ | -------------------------------------------- |
| `.off` (default)         | The anchor jumps to each fix                 |
| `.interpolate(seconds:)` | The anchor glides to each fix over that time |

Only the anchor that `MultiSetARView` owns is smoothed. The first placement, and the first fix after the scene was out of place, still jump. `mapAlignment` and `geoAlignment` report the accepted fix at once; `deviceGeolocation()` and `deviceMapPose()` use the anchor as shown, so their answers match the screen.

***

## Related

* [MultiSetCallback](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetcallback.md)
* [LocalizationResult](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/localizationresult.md)
* [Lifecycle and AR Runtimes](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/lifecycle-and-runtimes.md)
* [GeoPose Support](https://docs.multiset.ai/fundamentals/localization/geopose-support.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/polling-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
