1

I need to be able to perform a long click on a Marker in Google Maps for Android. More precisely on a Cluster, implemented through the use of the Google Maps Utils library (a Cluster is still considered a Marker by Google Maps).

I have found that the answer to the following question could be a potential workaround : Draggable Marker solution

The long click behaviour works as intended, but I want to completely cancel/override the dragging behaviour. I have managed to stop it by immediately setting the Marker to its current position once the dragging starts like so :

/**
 * Listens to long clicks on markers
 */
private GoogleMap.OnMarkerDragListener myMarkerDragListener = new GoogleMap.OnMarkerDragListener() {

    private LatLng loc;

    @Override
    public void onMarkerDragStart(com.google.android.gms.maps.model.Marker marker) {
        // Saving position. Unfortunately it's already too late at this point,
        // the marker was already moved above the finger tap.
        this.loc = marker.getPosition(); 
        Log.i(TAG, "Started dragging.");
    }

    @Override
    public void onMarkerDragEnd(com.google.android.gms.maps.model.Marker marker) {
        Log.i(TAG, "Ended dragging.");
    }

    @Override
    public void onMarkerDrag(com.google.android.gms.maps.model.Marker marker) {
        // I prevent any further dragging here.
        marker.setPosition(this.loc);
        Log.i(TAG, "Dragging.");
    }
};

It works just fine, however the Marker keeps moving slightly above my finger once the dragging gets fired up, which is rather annoying. I can't find any way to reposition it on its original location.

TL;DR how to prevent the dragging and keep only the long click behaviour ? Any other workaround for a long click on a Marker/Cluster is welcome.

Community
  • 1
  • 1
tort
  • 55
  • 7

1 Answers1

0

friend uses this method in ondrag

marker.setPosition(marker.getPosition());