Remove bookmark when adding a new one

2
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

    @Override

    public void onMapClick(LatLng point) {


        MarkerOptions marker = new MarkerOptions().position(
                new LatLng(point.latitude, point.longitude)).title("New Marker");

        mMap.addMarker(marker);

        System.out.println(point.latitude+"---"+ point.longitude);
    }
});}}

In case that code adds a new marker on the map, plus every click I give adds a new marker, so I want to remove the old marker when adding a new one

    
asked by anonymous 21.11.2016 / 22:21

1 answer

0

mMap.setOnMapLongClickListener (new GoogleMap.OnMapLongClickListener () {

        @Override
        public void onMapLongClick(LatLng arg0) {
            if (marker != null) {
                marker.remove();
            }
            marker = mMap.addMarker(new MarkerOptions());
                    .position(
                            new LatLng(arg0.latitude,
                                    arg0.longitude))
                    .draggable(true).visible(true));
        }
    });}}
    
21.11.2016 / 23:48