document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Check device support for geo-tracking
  2. guard ARGeoTrackingConfiguration.isSupported else {
  3.     // Geo-tracking not supported on this device
  4.     return
  5. }
  6. // Check current location is supported for geo-tracking
  7. ARGeoTrackingConfiguration.checkAvailability { (available, error) in
  8.     guard available else {
  9.         // Geo-tracking not supported at current location
  10.         return
  11.     }
  12.     // Run ARSession
  13.     let arView = ARView()
  14.     arView.session.run(ARGeoTrackingConfiguration())
  15. }
  16. // Create coordinates
  17. let coordinate = CLLocationCoordinate2D(latitude: 37.795313, longitude: -122.393792)
  18.  
  19. // Create Location Anchor
  20. let geoAnchor = ARGeoAnchor(name: "Ferry Building", coordinate: coordinate)
  21.  
  22. // Add Location Anchor to session
  23. arView.session.add(anchor: geoAnchor)
  24.  
  25. // Create a RealityKit anchor entity
  26. let geoAnchorEntity = AnchorEntity(anchor: geoAnchor)
  27.  
  28. // Anchor content under the RealityKit anchor
  29. geoAnchorEntity.addChild(generateSignEntity())
  30.  
  31. // Add the RealityKit anchor to the scene
  32. arView.scene.addAnchor(geoAnchorEntity)
  33.  
  34. // Create a new entity for our virtual content
  35. let signEntity = generateSignEntity();
  36.  
  37. // Add the virtual content entity to the Geo Anchor entity
  38. geoAnchorEntity.addChild(signEntity)
  39.  
  40. // Rotate text to face the city
  41. let orientation = simd_quatf.init(angle: -Float.pi / 3.5, axis: SIMD3<Float>(0, 1, 0))
  42. signEntity.setOrientation(orientation, relativeTo: geoAnchorEntity)
  43.  
  44. // Elevate text to 35 meters above ground level
  45. let position = SIMD3<Float>(0, 35, 0)
  46. signEntity.setPosition(position, relativeTo: geoAnchorEntity)
');