Disable onMarkerClickListener completely in Maps API v2

不打扰是莪最后的温柔 提交于 2019-12-03 15:37:20

问题


I want to disable clicking/tapping on map markers. I know you can disable default behavior by setting up an empty map.setOnMarkerClickListener and return true; However, this still takes the tap as clicking on the marker. I want to pass the tap on to the onMapClickListener.

In my app, tapping the map moves a marker around, and if you're tapping close to where the marker is already, it just thinks you're tapping the marker! You would think there is a Marker.setClickable method but there isn't.


回答1:


Just override the onclick event:

map.setOnMarkerClickListener(new OnMarkerClickListener() {
    public boolean onMarkerClick(Marker arg0) {
        return true;
    }
});



回答2:


i have two suggestions:

if i understood right, you want to offer the functionality to place a marker on the map, right?! If you cannot remove the setOnMarkerClickListener, did you tried to draw at the map and "convert" your drawing to a Marker in the end. (get 'LatLng' from drawing and create a Marker).

actually the second suggestion isn't really a good one (depending if you can zoom/move your map). I had a similar task and we used an transparent overlay over the map, which handled all user input and delegates it. but we didn`t had the functionality of zoom and move, which would be pain in the ass...




回答3:


map.setOnMarkerClickListener(null); try this




回答4:


class MyInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
     @Override
     public View getInfoContents(Marker mar)
     {
         return null;
     }
     @Override
     public View getInfoWindow(Marker mar)
     {
         return null;
     }
}

gmap.setInfoWindowAdapter(new MyInfoWindowAdapter);

Try this code above. This will set your infowindow to null.




回答5:


Apply OnMarkerClickListenerto your map. Implement onMarkerClick()method and returnfalse

googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
    public boolean onMarkerClick(Marker marker) {
        return true;
    }
});



回答6:


It is not necessary to implement OnMarkerClickListner. Just try to remove this statement

map.setOnMarkerClickListner(this)

from your code and I hope it will solve your problem.



来源:https://stackoverflow.com/questions/15401988/disable-onmarkerclicklistener-completely-in-maps-api-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!