# Using Device Maps Source: https://www.nianticspatial.com/docs/nsdk/how-to/vps/using_device_maps/?platform=kotlin > **Caution:** > > **Attention!** > > This feature is experimental and may not work as expected. For more information about it, see the [Device Mapping Feature page](https://www.nianticspatial.com/docs/nsdk/features/device_mapping/). # How to Place Virtual Content Using a Device Map Now that we have created a device map and saved it to a file, we can read it to place virtual objects in the AR scene. In this how-to, we will cover reading a device map file into your Kotlin project and how to use it to place content. ## Prerequisites Before you start, complete [How to Create a Device Map](https://www.nianticspatial.com/docs/nsdk/how-to/vps/adding_device_mapping/). You will need the Kotlin project from that tutorial for this one. ## Loading a Device Map Before we can localize to a saved device map, the map data must be loaded into the `MappingStorageSession` and a root anchor must be created for the VPS2 session to track. Create the map storage and VPS2 sessions from your `NSDKSession`: ```kotlin val mapStoreSession = nsdkSession.mapStore.acquire() val vps2Session = nsdkSession.vps2.acquire() ``` Load the map data from disk and add it to storage: ```kotlin // Read the saved map and add it to storage val mapData = File(context.filesDir, fileName).readBytes() mapStoreSession.add(mapData) // Create the root anchor payload from the loaded map val rootAnchorPayload = mapStoreSession.createRootAnchor() ?: error("Failed to get root anchor for loaded map.") ``` > **Caution:** > > `add()` **appends** to existing storage. If you want to replace the current map rather than merge with it, call `mapStoreSession.clear()` before `add()`. Do **not** call `clear()` while VPS is running -- stop the VPS2 session first. ## Configuring and Starting VPS2 Configure the VPS2 session for device-map-only localization, then start it and begin tracking the root anchor: ```kotlin val vps2Config = Vps2Config( enableUniversalLocalization = false, enableVpsMapLocalization = false, enableDeviceMapLocalization = true ) vps2Session.configure(vps2Config) vps2Session.start() val anchorId = vps2Session.trackAnchor(rootAnchorPayload) ``` ## Tracking Anchor Updates Collect `vps2Session.anchorUpdates` to receive per-frame pose updates for tracked anchors: ```kotlin coroutineScope.launch { vps2Session.anchorUpdates.collect { update -> // Filter for the anchor we care about if (!update.uuid.contentEquals(anchorId)) return@collect when (update.trackingState) { AnchorTrackingState.TRACKED -> { // Localization succeeded -- use the anchor's transform to position content val transform = update.anchorToLocalTrackingTransform } else -> { // Still localizing... } } } } ``` The `anchorToLocalTrackingTransform` represents the anchor's pose in the current AR session coordinate space. ## Placing Virtual Content Use the anchor's transform to position content in the scene. For example, convert it to a 4x4 matrix and apply it to a scene node: ```kotlin val matrix = FloatArray(16) update.anchorToLocalTrackingTransform.toMatrix(matrix, 0) // Apply `matrix` to your 3D content's world transform ``` For more details on placing content relative to anchors, see [Placing Virtual Content with VPS2](https://www.nianticspatial.com/docs/nsdk/how-to/vps2/placing_virtual_content/#place-content-relative-to-an-anchor). ## Extending an Existing Map Once the map data is loaded into storage, it behaves just as it did when first created. You can start a new mapping session to append additional scan data to the existing map and save the result, allowing you to build up a map incrementally across multiple sessions. ## Stopping When you are done tracking, remove the anchor, stop the sessions, and release resources: ```kotlin vps2Session.removeAnchor(anchorId) vps2Session.stop() vps2Session.close() ```