16

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.

Flyview
  • 1,622
  • 1
  • 25
  • 39
  • did you find a solution? – Patrick Mar 25 '13 at 17:48
  • @Patrick No I did not. – Flyview Mar 25 '13 at 21:12
  • 1
    I found the solution in this post: http://stackoverflow.com/questions/14497734/dont-snap-to-marker-after-click-in-android-map-v2 basically return true and call onMapClick on it's listener. Works for me. – Patrick Mar 25 '13 at 23:51
  • 2
    @Patrick that seems to work but it isn't perfect. Here's why. You have a marker. You tap near it, onMarkerClick gets triggered, passes it on to onMapClick. However, it passes the marker.getPosition() to onMapClick, not the actual tap position. So tapping anywhere near a marker is the same as tapping on that marker. How do I get the real position of the tap? – Flyview Mar 26 '13 at 04:15
  • oohh. Had not realized that. off the top of my head I don't know. – Patrick Mar 26 '13 at 14:31
  • Pretty much the exact same issue: http://stackoverflow.com/questions/17884401/google-maps-api-v2-how-to-make-markers-non-clickable – Flyview Oct 12 '13 at 05:22
  • Hello, i look many things about it but i basically solved this by running the method which should run on mapclick at markerclick. It solved. Simple. You should try it – alicanbatur Jan 06 '14 at 00:32
  • 1
    @alicanbatur as said above - you don't know which pixel of marker was clicked, you can only use marker position – tomash Feb 11 '14 at 15:17
  • @Flyview - Did you figure out a solution? I want to do the same thing, handle map click rather than marker click events. – Justin Nov 29 '16 at 14:41
  • @Justin no unfortunately I never did. I would have posted an answer! Please do if you figure it out. – Flyview Nov 30 '16 at 03:51
  • @Flyview, I do have a solution for this. See my comment on a duplicate question over at: http://stackoverflow.com/a/41867025/1669870 – mstenroos Jan 27 '17 at 14:19

6 Answers6

9

Just override the onclick event:

map.setOnMarkerClickListener(new OnMarkerClickListener() {
    public boolean onMarkerClick(Marker arg0) {
        return true;
    }
});
Victor Pinto
  • 447
  • 6
  • 8
0

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...

longi
  • 10,071
  • 8
  • 51
  • 86
  • 1
    No, I am not trying to put a marker on the map. I am trying to disable google's onMarkerClickListener and pass the tap to onMapClickListener. – Flyview Oct 27 '13 at 01:17
-1

map.setOnMarkerClickListener(null); try this

  • 3
    Doesn't work. It's as if you don't set your own listener at all and default behavior takes over. – Flyview Oct 21 '13 at 23:09
-1
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.

johntheripp3r
  • 1,008
  • 6
  • 15
  • This answer is wrong. Setting a custom ``InfoWindowAdapter`` to return null just means the default ``InfoWindowAdapter`` is used. This results in stock behavior. – zyamys Nov 25 '15 at 15:05
-1

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

googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
    public boolean onMarkerClick(Marker marker) {
        return true;
    }
});
Namrata
  • 1,624
  • 1
  • 15
  • 28
-3

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.

Karan Nagpal
  • 502
  • 1
  • 8
  • 18