Remove previous Marker and add new Marker in Google Map v2

前端 未结 8 869
不思量自难忘°
不思量自难忘° 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条回答
  •  Happy的楠姐
    2021-02-05 08:00

    Just reposting the answer of Anthony.

    The method signature for addMarker is:

    public final Marker addMarker (MarkerOptions options) So when you add a marker to a GoogleMap by specifying the options for the marker, you should save the Marker object that is returned (instead of the MarkerOptions object that you used to create it). This object allows you to change the marker state later on. When you are finished with the marker, you can call Marker.remove() to remove it from the map.

    As an aside, if you only want to hide it temporarily, you can toggle the visibility of the marker by calling Marker.setVisible(boolean).

    You can find the answer here Remove a marker from a GoogleMap

提交回复
热议问题