# Using Device Maps Source: https://www.nianticspatial.com/docs/nsdk/how-to/vps/using_device_maps/?platform=swift > **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 Swift 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 Swift 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 map storage and a root anchor must be created for the VPS2 session to track. Create the map storage and the VPS2 session from your `NSDKSession`: ```swift let mapStorage = nsdkSession.acquireMapStorage() let vps2Session = nsdkSession.acquireVps2Session() ``` Load the map data from disk and add it to storage: ```swift // Read the saved map and add it to storage let mapData = try Data(contentsOf: mapFileURL) let mapBuffer = NSDKBuffer(data: mapData) try mapStorage.addMap(map: mapBuffer) // Create the root anchor payload from the loaded map guard let anchorPayload = mapStorage.createRootAnchor() else { print("Failed to get root anchor for loaded map.") return } ``` > **Caution:** > > `addMap()` **appends** to existing storage. If you want to replace the current map rather than merge with it, call `mapStorage.clear()` before `addMap()`. 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: ```swift var vpsConfig = NSDKVps2Session.Configuration() vpsConfig.deviceMapLocalizationEnabled = true vpsConfig.universalLocalizationEnabled = false vpsConfig.vpsMapLocalizationEnabled = false try vps2Session.configure(with: vpsConfig) vps2Session.start() let anchorId = try vps2Session.trackAnchor(payload: anchorPayload) ``` ## Tracking Anchor Updates Subscribe to `vps2Session.anchorUpdated` to receive per-frame pose updates for tracked anchors: ```swift vps2Session.anchorUpdated .receive(on: DispatchQueue.main) .sink { [weak self] anchorId, update in guard let trackingData = update.trackingData else { return } let transform = trackingData.targetAnchorTransform // Use this transform to position content relative to the anchor } .store(in: &cancellables) ``` The `targetAnchorTransform` is a `simd_float4x4` matrix representing 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, with RealityKit: ```swift // When anchor tracking data arrives, update your content's transform if let trackingData = update.trackingData { myEntity.transform = Transform(matrix: trackingData.targetAnchorTransform) } ``` 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 and stop the session: ```swift _ = vps2Session.removeAnchor(withId: anchorId) vps2Session.stop() ```