Remove previous Marker and add new Marker in Google Map v2

前端 未结 8 745
不思量自难忘°
不思量自难忘° 2021-02-05 07:40

I want to remove a current marker after long click on map anywhere and recreate a new marker at that point. I have cleared google map on long click on map and new marker is crea

8条回答
  •  孤独总比滥情好
    2021-02-05 07:58

    Just clear the google map before adding marker. Like this:

    @Override
    public void onMapLongClick(LatLng latLng) {
        googleMap.clear();
    
        googleMap.addMarker(new MarkerOptions()
                .position(latLng)
                .title(latLng.toString())
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
    }
    

提交回复
热议问题