Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Check device support for geo-tracking
- guard ARGeoTrackingConfiguration.isSupported else {
- // Geo-tracking not supported on this device
- return
- }
- // Check current location is supported for geo-tracking
- ARGeoTrackingConfiguration.checkAvailability { (available, error) in
- guard available else {
- // Geo-tracking not supported at current location
- return
- }
- // Run ARSession
- let arView = ARView()
- arView.session.run(ARGeoTrackingConfiguration())
- }
- // Create coordinates
- let coordinate = CLLocationCoordinate2D(latitude: 37.795313, longitude: -122.393792)
- // Create Location Anchor
- let geoAnchor = ARGeoAnchor(name: "Ferry Building", coordinate: coordinate)
- // Add Location Anchor to session
- arView.session.add(anchor: geoAnchor)
- // Create a RealityKit anchor entity
- let geoAnchorEntity = AnchorEntity(anchor: geoAnchor)
- // Anchor content under the RealityKit anchor
- geoAnchorEntity.addChild(generateSignEntity())
- // Add the RealityKit anchor to the scene
- arView.scene.addAnchor(geoAnchorEntity)
- // Create a new entity for our virtual content
- let signEntity = generateSignEntity();
- // Add the virtual content entity to the Geo Anchor entity
- geoAnchorEntity.addChild(signEntity)
- // Rotate text to face the city
- let orientation = simd_quatf.init(angle: -Float.pi / 3.5, axis: SIMD3<Float>(0, 1, 0))
- signEntity.setOrientation(orientation, relativeTo: geoAnchorEntity)
- // Elevate text to 35 meters above ground level
- let position = SIMD3<Float>(0, 35, 0)
- signEntity.setPosition(position, relativeTo: geoAnchorEntity)
Advertisement
Add Comment
Please, Sign In to add comment