0

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?

BBonDoo
  • 766
  • 5
  • 14

1 Answers1

1

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?

Community
  • 1
  • 1
Martynas Jurkus
  • 9,231
  • 13
  • 59
  • 101
  • Then could you elaborate what I'm missing? – Martynas Jurkus Feb 11 '13 at 14:39
  • @Martynas...hahaha,,.so sorry...I don't mean your answer is wrong...Your answer for Q1 is right and what I do know well, but I am looking for another answer. And for Q2, I cannot fully understand what you say. I would like to find my answer in such control statement like "if","for" etc. Your answer is very excellent. – BBonDoo Feb 12 '13 at 02:47
  • @Martynas..I updated my question, so sorry I did not explain what I want to query fully. – BBonDoo Feb 12 '13 at 03:00
  • @Martynas..Thanks for your comment...you did link a good reference...it helped me....thanks a lot.. – BBonDoo Feb 13 '13 at 10:43
  • @Martynas..LOL...Still now I am looking for the answer of my question. – BBonDoo Feb 13 '13 at 15:24