title: ARCore: How can i place an anchor of the object on a horizontal surface parallelly(not in the air)?
body: <p>I'm currently working on Indoor navigation with ARCore from source to destination place. So i want to load navigation arrows from source to destination place on a horizontal surface(land) parallelly with zero height(not in the air) from surface. I tried many solutions and documentation of ARCore but didn't get the proper and accurate output.</p>
  <p>I want to place navigation arrow parallelly to the bottom horizontal surface with accuracy like this <a href="https://i.stack.imgur.com/2nMpA.jpg" rel="nofollow noreferrer">enter image description here</a>, but sometimes it's loads inside the surface or not accurate. <a href="https://i.stack.imgur.com/lsN4O.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>Can anyone please help me in this case? Here is my function for place object,</p>
  <pre><code>public int placeItem(Renderable r, double dist, float angle, float rotation, float height, boolean rotate) {
  
  Session session = fragment.getArSceneView().getSession();
  Frame frame = fragment.getArSceneView().getArFrame();
  //Get some anchors to anchor our item to
  //Get the phone's pose in ARCore
  Pose deviceOrientedPose = frame.getCamera().getPose().compose(
              Pose.makeTranslation(0.0f, -0.1f, 0.0f));
  
  //Get the phone's pose in relation to the real world
  float heading = visualAnchorCompass.getHeading(session, frame, false);
  float cameraFrame = VisualAnchorCompass.getAngleFromPose(deviceOrientedPose);
  
  //Rotate around y axis...
  float offset_by = (heading + cameraFrame) % 360;
  float from_camera = (rotation - offset_by + 360) % 360;
  float rotAngle = (-from_camera + 360) % 360;
  Quaternion qt = Quaternion.axisAngle(Vector3.up(), rotAngle);
  
  //Build the node
  Anchor anchor = session.createAnchor(deviceOrientedPose);
  AnchorNode anchorNode = new AnchorNode(anchor);
  anchorNode.setParent(fragment.getArSceneView().getScene());
  Node node = new Node();
  node.setParent(anchorNode);
  node.setRenderable(r);
  //Set rotation
  if (rotate)
      node.setLocalRotation(qt);
  
  //Set angle
  float from_camera1 = (angle - offset_by + 360) % 360;
  float angrad = ((-from_camera1 + 360) % 360);
  Log.d(TAG, &quot;drawing... &quot; + rotation + &quot; intended angle:&quot; + angle + &quot; angrad:&quot; + heading + &quot;,campose&quot; + cameraFrame);
  
  Vector3 pos = new Vector3(-(float) dist * (float) Math.sin(Math.toRadians(angrad)), 
  0, -(float) dist * (float) Math.cos(Math.toRadians(angrad)));
  
  float[] vec = deviceOrientedPose.getTranslation();
  Vector3 camPos = new Vector3(vec[0], vec[1], vec[2]);
  Log.d(TAG, &quot;xyz: &quot; + pos.x + &quot;,&quot; + pos.z);
  pos = Vector3.add(camPos, pos);
  node.setLocalPosition(pos);
  item_counter++;
  items.put(item_counter, node);
  return item_counter; 
  }
  </code></pre>