如何删除谷歌地图V2中的标记? [英] How to remove the marker in Google map v2?

查看:123
本文介绍了如何删除谷歌地图V2中的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下方法在地图上添加了标记,并且还保留了标记记录

I added the marker on the map using following method and also kept the marker record

public static void  showallLocations() 
    {
        ArrayList<LinkedHashMap<String, String>> listshow=latLngStoragepreference.getLatlng();
        markerlist=new ArrayList<Marker>();// to keep the marker record so that later we can delete
        if(listshow.size()>0)
        {
        for(int i=0;i<listshow.size();i++)
        {
        LinkedHashMap<String, String> Linkedhashmap=listshow.get(i);

        Set mapSet = (Set) Linkedhashmap.entrySet();
        //Create iterator on Set 
        Iterator mapIterator = mapSet.iterator();

        Map.Entry mapEntry = (Map.Entry) mapIterator.next();
        // getKey Method of HashMap access a key of map
        String keyValue = (String) mapEntry.getKey();
        //getValue method returns corresponding key's value
        String value = (String) mapEntry.getValue();
        String[] parts=value.split("#");
        String Latitude=parts[0];
        String Longitude=parts[1];
        Double Latitudeconverted=Double.parseDouble(Latitude);
        Double Longitudeconverted=Double.parseDouble(Longitude);
        System.out.println(Latitudeconverted+""+Longitudeconverted);
        //show on map
        LatLng latLngs=new LatLng(Latitudeconverted, Longitudeconverted);

        Marker marker=map.addMarker(new MarkerOptions()
        .position(
                latLngs)
                .title(keyValue)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_navigate_to)));
        markerlist.add(marker);// keeping the record of marker object

        }
        }


    }

在自定义baseadapter中,我尝试删除标记,但是 marker.remove()不工作

in custom baseadapter, I tried to remove the marker but marker.remove() is not working

holder.btnDeletelocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


        Marker marker=  MainActivity.markerlist.get(position);
        Log.d("MARKERlist before Remove", MainActivity.markerlist.toString());

        Log.d("MARKER Title",marker.getTitle());


        marker.remove();
        marker.setVisible(false);
        Log.d("MARKERlist after Remove", MainActivity.markerlist.toString());



            notifyDataSetChanged();




            }
        });

请帮助如果有人经历过相同的情况。提前致谢

Please help If anybody had gone through the same. Thanks in advance

推荐答案

我谷歌搜索很多,发现不容易从地图上删除标记,
每当将标记添加到地图时,请不要忘记保存其记录,例如将其添加到Map或ArrayList中。

I Googled lot and found there isn't easy way to remove the marker from map, whenever you add the marker to map don't forget to keep its record, like adding it to Map or ArrayList.

your_google_map_obj.addMarker(new MarkerOptions()) //this adds Marker on Google Map, you should know it always returns Marker object so that you can use it later especially for removal.

so Marker marker = your_google_map_obj.addMarker(new MarkerOptions() code>将此标记对象添加到列表或映射 markerArraylist.add(marker); 然后您可以轻松地从列表中提取标记
Marker marker = markerArraylist.get(index); 然后调用 marker.remove();

so Marker marker=your_google_map_obj.addMarker(new MarkerOptions()) add this marker object to list or map markerArraylist.add(marker); then easily you can extract marker from list by Marker marker=markerArraylist.get(index); and then call marker.remove();

这篇关于如何删除谷歌地图V2中的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆