3

I have map and marker on it. I need to do when user pushes this marker or pushes near this marker that app wil do "onMapClick listener" and return me coordinates of click instead of "onMarkerClick". It is somehow possible to ignore marker click for one marker and make onMapClick instead?

I tried this, but it don't do anything:

mMap.setOnMarkerClickListener(new OnMarkerClickListener(){

      @Override
      public boolean onMarkerClick(Marker arg0) {             
           if(arg0.getSnippet().equals("bad_marker")){

                   mMap.setOnMapClickListener(new OnMapClickListener() {        
                  @Override
                  public void onMapClick(LatLng latLng) {                             
                      mapClick(latLng); 
                  }       
             });
             }});
Wouter J
  • 39,482
  • 15
  • 97
  • 108
Eddwhis
  • 984
  • 2
  • 14
  • 31
  • Your question is not clear. Also, I wouldn't set a listener inside another listener in the way you did. Do you need to get the marker position you have just clicked? If so, there's a method for that: getPosition(). – fasteque Oct 17 '13 at 08:09
  • I tried this method - but it returns clicked marker coordinates, but I need accurate click coordinates. Because click can be near marker position, but it still cals onMarkerClickListener() – Eddwhis Oct 17 '13 at 08:12
  • I have the same problem: http://stackoverflow.com/questions/15401988/disable-onmarkerclicklistener-completely-in-maps-api-v2 – Flyview Nov 20 '13 at 03:12

1 Answers1

0

Save your marker in a class variable, so you have reference to it.

Then set an OnMarkerClickListener and check if arg0 is your marker: if so, do what you have to do if the user clicks on that marker.

Also set an setOnMapClickListener and check if latLng given to you by onMapClick is close to the position of your marker. You have your marker as class variable, so you can get its position and check it against the position on the map where the user clicked.

fasteque
  • 4,209
  • 8
  • 35
  • 49