WPSSession
↳ extends SessionBase
A session for World Positioning System (WPS) functionality. WPS provides the 3D position and orientation of the device in geographic coordinates as an alternative to using device GPS and compass heading data. WPS provides greater accuracy and frame-to-frame stability than standard GPS positioning, making it more suitable for AR applications. As the user moves around, WPS maintains the device's position, making it suitable for continuous use over long periods of time and long distances. WPS will work in any location where the phone has a GPS signal, but the accuracy will vary depending on GPS accuracy. ### Usage 1. Acquire the WPS session:
kotlin val wpsSession = ardkSession.wps.acquire() 2. Configure the session (optional - defaults are usually sufficient): kotlin val config = WPSConfig( enableSmoothing = true, framerate = 120 ) wpsSession.configure(config) 3. Start the session: kotlin wpsSession.start() 4. Poll for location updates regularly: kotlin coroutineScope.launch { while (trackingStarted) { delay(1000) // Update every second // Check feature status val featureStatus = wpsSession.featureStatus() if (!featureStatus.isOk()) { println("WPS has encountered an error") } // Get the latest location estimate when (val result = wpsSession.getLatestLocation()) { is ARDKResult.Success -> { val location = result.value println("GPS: ${location.referenceLatitudeDegrees}, ${location.referenceLongitudeDegrees}") println("Altitude: ${location.referenceAltitudeMetres} meters") // Use the transformation matrix for coordinate conversions val worldPosition = location.trackingToRelativeEdn // Place AR content using world position } is ARDKResult.Error -> { when (result.code) { WPSError.NOT_INITIALIZED -> println("WPS still initializing...") WPSError.NO_GNSS -> println("No GPS signal available") WPSError.NO_HEADING -> println("No compass data available") WPSError.TRACKING_FAILED -> println("WPS tracking failed") else -> println("WPS error: ${result.code}") } } } } } 5. Clean up when done: kotlin wpsSession.stop() wpsSession.close() ### Advanced Features Converting specific poses to geolocations: kotlin val cameraPose = frame.camera.pose when (val result = wpsSession.getDevicePoseAsGeolocation(cameraPose)) { is ARDKResult.Success -> { val geolocation = result.value println("Pose location: ${geolocation.latitude}, ${geolocation.longitude}") } is ARDKResult.Error -> { println("Could not get geolocation for pose: ${result.code}") } } Declaration
class WPSSessionProperties
| Name | Type | Summary |
|---|---|---|
| ardkHandle | Long | - |
| defaultPollingIntervalMs | Long | - |
Functions
| Name | Type | Summary |
|---|---|---|
| configure | void | Configures the session with the specified settings. Attention: This method must be called while the session is stopped, or else 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. Note: The WPS settings should be kept at their default value in almost all instances. |
| featureStatus | FeatureStatus | 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. ### Example kotlin val status = wpsSession.featureStatus() if (!status.isOk()) { println("WPS has encountered an error") } |
| geolocationUpdates | Flow<NSDKResult<GeolocationData, WPSError>> | Flow of geolocation updates. This is the primary way to receive geolocation updates in Kotlin. The Flow polls [getDevicePoseAsGeolocation] at regular intervals using the provided pose. |
| getDevicePoseAsGeolocation | NSDKResult<GeolocationData, WPSError> | Use WPS to get an estimated geolocation for a pose in AR space. |
| getLatestLocation | NSDKResult<WPSLocation, WPSError> | Gets the transform of the latest geolocation estimate. This exposes the low level data that can be used to pin geolocated content into the AR coordinate system. To retrieve simplified device specific coordinates and heading, see [getDevicePoseAsGeolocation]. |
| onDestroy | void | - |
| onInit | void | - |
| start | void | Starts the WPS system. This begins the process of collecting some local device sensor data that is needed for localization. |
| stop | void | Stops the WPS system. This halts all WPS processing. The session can be reconfigured and restarted after stopping. |