Skip to main content
API Reference com.nianticspatial.nsdk.vps

VPSSession

↳ extends SessionBase
A session for Visual Positioning System (VPS) functionality. VPSSession provides capabilities for precise localization using visual features. VPS can determine device position and orientation relative to a pre-mapped environment, enabling persistent AR experiences that maintain accuracy across sessions. ### Usage 1. Acquire the VPS session: kotlin val vpsSession = ardkSession.vps.acquire() 2. Configure the session (must be done before starting): kotlin val config = VPSConfig( enableContinuousLocalization = true, enableTemporalFusion = true ) vpsSession.configure(config) 3. Start the session: kotlin vpsSession.start() 4. Track an anchor using a payload: A VPS payload can be obtained from the "blob" field in the Geospatial Browser, or via [getAnchorPayload] for user-generated anchors. kotlin val anchorId = vpsSession.trackAnchor(anchorPayload) 5. Poll for anchor updates regularly: kotlin coroutineScope.launch { while (trackingStarted) { delay(500) // Update every 500ms val update = vpsSession.getAnchorUpdate(anchorId) when (update.trackingState) { AnchorTrackingState.NOT_TRACKED -> println("Anchor not tracked - waiting for localization") AnchorTrackingState.LIMITED -> println("Limited tracking - pose may be unreliable") AnchorTrackingState.TRACKED -> { // Anchor is fully tracked - safe to place content val matrix = FloatArray(16) update.anchorToLocalTrackingTransform.toMatrix(matrix, 0) // Update your AR content with the anchor's transform } } } } 6. Clean up when done: kotlin vpsSession.stop() vpsSession.close() ### Advanced Features Creating new anchors: kotlin val cameraPose = frame.camera.getDisplayOrientedPose() val newAnchorId = vpsSession.createAnchor(cameraPose) Getting anchor payload for sharing: kotlin val payload = vpsSession.getAnchorPayload(newAnchorId) if (payload != null) { // Store or share this payload for future sessions } Converting poses to GPS coordinates: kotlin val result = vpsSession.getDevicePoseAsGeolocation(frame.camera.pose) when (result) { is ARDKResult.Success -> { val geolocation = result.value println("Lat: ${geolocation.latitude}, Lon: ${geolocation.longitude}") } is ARDKResult.Error -> { println("Geolocation error: ${result.code}") } } Getting session ID for debugging: kotlin val sessionId = vpsSession.getSessionId() println("VPS Session ID: ${sessionId?.joinToString("") { "%02x".format(it) }}")

Declaration

class VPSSession

Properties

NameTypeSummary
anchorUpdatesFlow<AnchorUpdate>
Flow of anchor updates for all tracked anchors. This Flow emits [AnchorUpdate] whenever any tracked anchor receives an update. Anchors are automatically added to tracked anchors when created via [trackAnchor] or [createAnchor], and automatically removed when [removeAnchor] is called or when the anchor is no longer available.
ardkHandleLong
-
pollingIntervalMsLong
-

Functions

NameTypeSummary
configurevoid
Configures the session with the specified settings. Attention: This method must be called while the session is stopped, or configuration will fail. In that case, while this function returns without throwing, configuration will still fail asynchronously. Use [featureStatus] to check that configuration has not failed.
createAnchorUUID
Requests to create an anchor at the specified pose. This will create an anchor relative to the currently tracked location that can be used to localize in future sessions. Attention: This method requires that the session has successfully localized (an anchor was successfully tracked) before it returns a valid anchor payload for future sessions. After creating an anchor, regularly poll [getAnchorUpdate] to get the anchor's updated pose.
featureStatusFeatureStatus
Reports errors that have occurred within processes running inside this feature. Check this periodically to see if any errors have occurred with processes running inside this feature. Once an error has been flagged, it will remain flagged until the culprit process has been run again and completed successfully.
getAnchorPayloadString?
Gets the payload data of a specified anchor. The payload encodes the data needed to localize an anchor across multiple devices or sessions. It can be shared or stored for later use with [trackAnchor]. Payloads are only available after the anchor is tracked.
getAnchorUpdateAnchorUpdate
Gets the latest tracking update for a specified anchor. Call this regularly to get updated anchor poses as the device moves and VPS refines the localization.
getDevicePoseAsGeolocationNSDKResult<GeolocationData, VpsGraphOperationError>
Use VPS to get an estimated geolocation for a pose in AR space. Requires that the session was configured with enableGpsCorrectionForContinuousLocalization enabled and the user be currently localized. Note: Test (private) scans currently don't have GPS data so they cannot be used with this functionality.
getSessionIdUUID?
Gets the unique session identifier for this VPS session. The session identifier can be used to distinguish between different VPS sessions, useful for debugging. The ID only exists after at least one anchor has been created via [createAnchor] or [trackAnchor].
getTrackedAnchorsSet<UUID>
Get the set of currently tracked anchor UUIDs.
onDestroyvoid
-
onInitvoid
-
removeAnchorvoid
Request to stop tracking an anchor. Once removed, the anchor will no longer receive updates or consume processing resources. The anchor will automatically be removed from tracked anchors and will stop emitting updates through the [anchorUpdates] Flow.
startvoid
Starts the VPS session. This begins the process of collecting some local device sensor data that is needed for localization. In order to actually localize, [trackAnchor] must be called.
stopvoid
Stops the VPS session. This halts all VPS processing and anchor tracking. The session can be reconfigured and restarted after stopping.
trackAnchorUUID
Requests to start tracking an anchor specified by a payload. A VPS payload contains all the data needed to localize at a VPS-activated location. A default payload for a VPS-activated location can be obtained from the "blob" field in the details view of an entry in the Geospatial Browser, or via [getAnchorPayload] for user-generated anchors. The anchor will automatically be added to tracked anchors and will emit updates through the [anchorUpdates] Flow.