dat-ng / ar-location-based-android

This AR app generally show where things are in the real-world by indicating where the app thinks they are over the camera view when the user holds the phone up and moves it about.
MIT License
203 stars 85 forks source link

OnClickListener for each ARPoint #4

Open hanilozmen opened 7 years ago

hanilozmen commented 7 years ago

First of all, thanks for this implementation. It is working as expected. By the way, getting gps location one time and making processes according to that fixed location provided me a more stable experience.

My question: I want to add onclick listener for each ARPoint so a detail page of that point will be opened. Do you have any suggestion or code snippet for this?

dat-ng commented 7 years ago

You should refactor View into ViewGroup, and the canvas overlay you added need to change to view. For view, you can implement onClick

2017-05-30 15:56 GMT+07:00 hanilozmen notifications@github.com:

First of all, thanks for this implementation. It is working as expected. By the way, getting gps location one time and making processes according to that fixed location provided me a more stable experience.

My question: I want to add onclick listener for each ARPoint so a detail page of that point will be opened. DO you have any suggestion or code snippet for this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dat-ng/ar-location-based-android/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOmjEI9C45lLO266jJMGdIJY2oGNXo_ks5r-9mmgaJpZM4NqAKv .

SankarGomathi commented 6 years ago

how to get the position in canvas ??

ShantiRanjanDas commented 6 years ago

I changed it , but the views are gone, can you change it in your library

Rich2k commented 6 months ago

It is possible to do this by storing the x/y position of the Circle drawn as well as it's radius and using onTouchEvent to capture the touched location.

Note this is NOT the best way to do this @dat-ng method is the correct way to do it

However if you're interested (sorry this is in Kotlin not Java)

override fun onTouchEvent(event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                val touchX = event.x
                val touchY = event.y

                // Calculate the distance from the touch point to the circles center
                val distance = Math.sqrt(((touchX - circleX).pow(2) + (touchY - circleY).pow(2)).toDouble())

                // Check if the touch is inside the circle
                if (distance <= circleRadius) {
                    // Touch is inside the circle
                    // Do Something Here
                }
            }
        }
        return true
    }