如何正确检测标记单击Sygic Map中的

时间:2019-01-08 09:37:35

标签: android kotlin sygic sygic-mobile-sdk sygic-maps

我每次使用MapGestureListener来比较单击区域的坐标和标记的坐标,如果它们位于相同的坐标,那么我很好,但是由于相对高度,它不起作用更改并不能确保获得点击位置的准确性。

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 个答案:

答案 0 :(得分:0)

我已经做到了,我只需要在MapGesture侦听器中调用“ requestObjectsAtPoint”并做一些变通方法,这是代码:

       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
        }
    })