如何从谷歌地图V2删除标记?

如何从谷歌地图V2删除标记?

问题描述:

我有两个选项上的标记攻上的选项删除标记时弹出一个alerdialog。现在,这个完美的作品,除非用户点击了删除标记选项,然后在警告对话框自败,但是标记仍然存在。当我再次点击该标记,然后选择删除,然后将其从地图中删除。很奇怪,我不知道为什么它这样做。

I have an alerdialog that pops up when tapping on the marker with two options, on of the options are to remove the marker. Now this works perfectly, except the user taps on the remove marker option and then the alert dialog dissapears but the marker is still there. When i tap the marker again and select remove, then it removes from the map. Really weird and i don't know why it is doing that.

下面是我的code:

 @Override
        public boolean onMarkerClick(final Marker marker) {
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context)
  .......

.setNegativeButton("Delete Marker",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            marker.remove();
                            dialog.cancel();

任何想法,为什么发生这种情况?

Any ideas why this is happening?

您的 marker.remove() code不起作用?

Your marker.remove() code does not work?

或者说你有什么实际的问题?

Or say what is your actual problem?

设置一个变量中的所有markder像

set All markder within a variable like

HashMap<Integer, Marker> myMarkersHash = new HashMap<Integer, Marker>();

,并把标记值

myMarkersHash.put(IndexValue, marker);

和显示/隐藏标记使用这种code

    myMarkersHash.get(IndexValue).setVisible(false);
// or
   myMarkersHash.get(IndexValue).setVisible(true);