0

我使用 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
        }
    })
4

1 回答 1

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
        }
    })
于 2019-01-09T12:31:16.720 回答