Skip to content

Instantly share code, notes, and snippets.

@aclima93
Last active August 21, 2018 14:58
Show Gist options
  • Save aclima93/cce1b50ad5f51111af019adbe1af91f8 to your computer and use it in GitHub Desktop.
Save aclima93/cce1b50ad5f51111af019adbe1af91f8 to your computer and use it in GitHub Desktop.
ARKit & CoreLocation + POI + AR Interaction
var sceneLocationView: SceneLocationView!
var pois: [PointOfInterest]!
var locationAnnotationNode2POI: [LocationTextAnnotationNode: PointOfInterest]!
var selectedPOI: PointOfInterest?
func setupARScene() {
// create AR scene
sceneLocationView = SceneLocationView()
view.addSubview(sceneLocationView)
// add tap gesture recognizer to AR scene's view
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleARObjectTap(gestureRecognizer:)))
sceneLocationView.addGestureRecognizer(tapGestureRecognizer)
}
@objc
func handleARObjectTap(gestureRecognizer: UITapGestureRecognizer) {
guard gestureRecognizer.view != nil else { return }
if gestureRecognizer.state == .ended {
// Look for an object directly under the touch location
let location: CGPoint = gestureRecognizer.location(in: sceneLocationView)
let hits = sceneLocationView.hitTest(location, options: nil)
if !hits.isEmpty {
// select the first match
if let tappedNode = hits.first?.node.parent as? LocationTextAnnotationNode {
if let poi = locationAnnotationNode2POI?[tappedNode] {
self.selectedPOI = poi
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment