appoly / ARCore-Location

Allows items to be placed within the AR world with real-world GPS coordinates using ARCore.
https://www.appoly.co.uk/arcore-location/
MIT License
478 stars 158 forks source link

touch the scene, get lat/long position and add new object with this coordinates #112

Open openmotion opened 4 years ago

openmotion commented 4 years ago

hello how can i get latitude / longitude when i touch a virtual ground

i added touchlistener to arsceneview arSceneView .getScene() .setOnTouchListener( (HitTestResult hitTestResult, MotionEvent event) -> { return gestureDetector.onTouchEvent(event); }); my gesture detector ` // Set up a tap gesture detector. gestureDetector = new GestureDetector( this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { onSingleTap(e); return true; }

                        @Override
                        public boolean onDown(MotionEvent e) {
                            return true;
                        }
                    });`

my onsingletap

`private void onSingleTap(MotionEvent tap) { Log.d(TAG,"single tap X1");

    float centerX = tap.getX();
    float centerY = tap.getY();

    Log.d(TAG,"centerX : "+centerX);
    Log.d(TAG,"centerY : "+centerY);

    Frame frame = arSceneView.getArFrame();
    if (frame != null) {
        Log.d(TAG,"single tap X2");

        Collection<Plane> planes = frame.getUpdatedTrackables(Plane.class);
        for (Plane plane : planes) {

            Log.d(TAG,"liste plan : "+plane.getType());

            if (plane.getTrackingState() == TrackingState.TRACKING && plane.getType() == Plane.Type.HORIZONTAL_UPWARD_FACING) {
                List<HitResult> hitResults = frame.hitTest(centerX, centerY);

                int count_hit = hitResults.size();
                        Log.d(TAG,"count_hit : "+count_hit);

                if (hitResults.size() > 0) {
                    Anchor Nanchor = hitResults.get(0).createAnchor(); // how can i have lat / lng coordinate here ? thanks ?
                    float[] Xaxis = Nanchor.getPose().getXAxis();
                    Log.d(TAG,"Xaxis : "+Xaxis[0]);
                    // return hitResults.get(0).createAnchor();
                }
            }
        }
    }
}`

thanks

VishalAr1996 commented 8 months ago

Hey had you found anything related to this??