Drag marker on on Single tap instead of LongClick

197 views Asked by At

I have functionality in my project in which I'm drawing a polygon line on Map Click and the user can edit that line by dragging the marker on any new location he wants.

But the issue I'm facing is this functionality activates on long-click of the marker as I'm using onMarkerDragListener callback for this.

What I want is the user only has to tap a marker and start dragging instead of hold the marker for 1 2 seconds and meanwhile accordingly I can update the polygons lines on Map.

This is how I'm currently doing :

@Override
public void onMapClick(LatLng latLng) {
    Marker marker = mMap.addMarker(new MarkerOptions()
            .position(latLng)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pointer))
            .draggable(true));

    marker.setTag(latLng);
    markerList.add(marker);
    latlngPoints.add(latLng);
    drawPolygon(latlngPoints);
    updateValueText();
}

mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
    @Override
    public void onMarkerDragStart(Marker marker) {
    }

    @Override
    public void onMarkerDrag(Marker marker) {
        updateMarkerLocation(marker, false);
    }

    @Override
    public void onMarkerDragEnd(Marker marker) {

        updateMarkerLocation(marker, true);
    }
});

public void updateMarkerLocation(Marker marker, boolean calculate) {
    LatLng latLng = (LatLng) marker.getTag();
    int position = latlngPoints.indexOf(latLng);
    latlngPoints.set(position, marker.getPosition());
    marker.setTag(marker.getPosition());
    drawPolygon(latlngPoints);
    if (calculate)
        updateValueText();
}

private void drawPolygon(List<LatLng> latLngList) {
    if (polygon != null) {
        polygon.remove();
    }

    PolygonOptions polygonOptions = new PolygonOptions();
    polygonOptions.fillColor(COLOR_LINE);
    polygonOptions.strokeColor(COLOR_POINT);
    polygonOptions.strokeWidth(LINE_WIDTH);
    polygonOptions.addAll(latLngList);
    polygon = mMap.addPolygon(polygonOptions);
}

This is the screenshot of the Activity :

enter image description here

Also, I want to add midPoints between polygon lines right now on MapCLick only a polygon line is drawn but I want to add a midpoint with a drawable on it between that line and that point should also b draggable if the user wants.

I have seen some questions on StackOverflow but didn't get any idea or clue how to do it some answers posted under questions are very old those methods are depreciated already. I read one answer in which the user said onToucEvent call back can do this functionality but didn't explain it how can we achieve it.

0

There are 0 answers