How to properly detect markerClick in Sygic Map

167 Views Asked by At

I used MapGestureListener to compare each time the coords of the clicked area and the coords of the marker and if they're at the same coords then I'm good to go but it just won't work because of the relative altitude change that doesn't assure the accuracy of getting the clicked position.

mpView.addMapGestureListener(object : MapGestureAdapter() {
        override fun onMapClicked(e: MotionEvent?, isTwoFingers: Boolean): Boolean {

            val clickedArea=mpView.geoCoordinatesFromPoint(Math.round(e!!.getX()), Math.round(e.getY()))
            for (marker : MapMarker in markerList )
            {

                val dist=clickedArea!!.distanceTo(marker.position)
                if (dist< 2)

                {
                    val positionMarker = markerList.indexOf(marker)
                    val positionLastMarker = markerList.indexOf(mSelectedMarker!!)
                    val markerNumber = positionMarker +1
                    val lastMarkerNumber = positionLastMarker + 1
                    travelStep = travelStepList.get(markerNumber -1)
                    configTeaser(travelStep)
                }
            }

            return false
        }
    })
1

There are 1 best solutions below

0
On BEST ANSWER

I've managed to do it , i just had to call the "requestObjectsAtPoint" inside the MapGesture listener and do some workaround ,here's the code :

       mpView.addMapGestureListener(object : MapGestureAdapter() {
        override fun onMapClicked(e: MotionEvent?, isTwoFingers: Boolean): Boolean {
            mpView.requestObjectsAtPoint(e!!.getX(),e.getY(), RequestObjectCallback { objects, x, y ->

                for (marker : ViewObject in objects )
                {
                    if (marker.objectType==1)
                    {
                        if ((marker as MapObject).mapObjectType==1)
                        {
                            val positionMarker = markerList.indexOf(marker)
                            val positionLastMarker = markerList.indexOf(mSelectedMarker!!)
                            val markerNumber = positionMarker +1
                            val lastMarkerNumber = positionLastMarker + 1
                            mSelectedMarker = marker as MapMarker
                            travelStep = travelStepList.get(markerNumber -1)
                            configTeaser(travelStep)
                        }
                    }


                }

            })

            return true
        }
    })