简体   繁体   中英

how to limit the number of the markers in Android Google Maps API v2?

My question refers to the new Google Maps API v2 in Android.

We can easily get the LatLng(point) on Google Maps, if setting the below;

@Override
    public void onMapClick(LatLng point) {

    }

And if want to add the marker whenever touching on Google Map, we do the below;

@Override
    public void onMapClick(LatLng point) {

        googleMap.addMarker(
                new MarkerOptions().
                position(point).
                title("Hello World"));
    }

Then we can get both the marker and LatLng(point) where we touch on map.

But the problem is that all markers DO NOT disappear whenever touching on map.

Question 1 : Whenever I touch on map, I want to add just the last marker on map. As you may know, to do this,we can add "googleMap.clear()" before adding "addmarker()" in the code. But does another method exist ?

Question 2 : When the only one marker exists on map,I want to add just my second marker on map using touching on the maps, "onMapClick". In short, I don't want to add the third marker on the map within "public void onMapClick(LatLng point){}". How?

Question 1: Try googleMap.clear() before adding new marker.

Question 2: Store markers you want to keep in a List and add them as needed.

Edit: Well then I would refer you to this question: How to remove single marker using Google Maps V2?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM